|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-31 23:17 UTC] daniele_dll at yahoo dot it
Description:
------------
Type casting a value on an if doesn't work!
If i compare a string value with the same value type casted to an int and this string doesn't contains a numeric value i recive a true from the boolean expression!
I've tried many combinations but all return the same result
Thanks for the help
Reproduce code:
---------------
<?php
$valore = 'qwerty';
if ($valore == (int)$valore)
{
echo "variable contains a valid numeric value!";
}
else
{
echo "variable doesn't contains a valid numeric value!";
}
?>
Expected result:
----------------
$valore == (int)$valore --> FALSE
variable doesn't contains a valid numeric value!
Actual result:
--------------
$valore == (int)$valore --> TRUE
variable contains a valid numeric value!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 03:00:01 2025 UTC |
I'll try to explain me ... $value = 'qwerty'; $value -> qwerty (int)$value -> 0 so ... how can be that 0 is equal to qwerty? Try this code too <?php $valore = 'qwerty'; $_v = intval($valore); echo ($valore) ? 'true ' : 'false '; echo ($_v) ? 'true ' : 'false '; if ($valore == $_v) { echo "variable ({$valore}) contains a valid numeric value ({$_v}) !"; } else { echo "variable doesn't contains a valid numeric value!"; } ?> The result is wrong!