php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36938 Type casting on boolean expressions doesn't work
Submitted: 2006-03-31 23:17 UTC Modified: 2006-04-01 09:55 UTC
From: daniele_dll at yahoo dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Windows XP SP2 - Fedora Core 4
Private report: No CVE-ID: None
 [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!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-31 23:25 UTC] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2006-04-01 09:33 UTC] daniele_dll at yahoo dot it
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!
 [2006-04-01 09:34 UTC] daniele_dll at yahoo dot it
ops, forgotten to re-open the report

sorry
 [2006-04-01 09:55 UTC] tony2001@php.net
0 == 0. This is expected.
No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 03:01:33 2025 UTC