ID: 26821
Updated by: [EMAIL PROTECTED]
Reported By: ivo at benetech dot org
Status: Bogus
Bug Type: Documentation problem
Operating System: Linux / RH 7.3
PHP Version: 4.3.4
New Comment:
As said by sniper: never ever compare different types like that!!!
In case $var is an int, you can do a $var < 0. In case $var is a
string, PHP don't know what to do (try this with Java or C++!).
Let your called functions return FALSE on error and everything works
fine. Or as an alternative, try something like
$var=somefunction();
if(is_integer($var)&&$var<0)
{
// Here comes the error-Processing
print("Error\n");
}
else
{
// Do something with $var
print $var;
}
Previous Comments:
------------------------------------------------------------------------
[2004-01-09 11:32:01] ivo at benetech dot org
> If someone asks you if A+B > 4 is, you wouldn't know what to
calculate...
I sincerely hope this would hold:
http://www.php.net/manual/en/language.operators.php#language.operators.precedence
....otherwise theres bigger problems.
If a statement such as
"some arbitrary string" < 0
is not to be trusted then the documentation should be updated to
reflect this. Currently it explains strong comparisons with '===', weak
with '==' but it does not mention < or >, ony obliquely and it
obviously does not.
(http://www.php.net/manual/en/types.comparisons.php)
p.s. I am working with a site that manipulates strings everywhere. most
functions return < 0 on error or the processed string if all goes well.
just finished updting it to return ints always & use references for
strings.
still think it's an outright bug or at least a documentation problem
due to all the 'weak' type comparison references & examples everywhere.
------------------------------------------------------------------------
[2004-01-09 11:04:29] [EMAIL PROTECTED]
Who wants to evaluate "NANC" < 0??? It _absolutely_ makes no sense. If
someone asks you if A+B > 4 is, you wouldn't know what to calculate...
FYI I've tried ivo's script. Under PHP 4.3.3 it produces "should
happen...but doesnt" and under 4.3.0 it's "should not happen...but
does".
------------------------------------------------------------------------
[2004-01-08 22:35:09] skissane at ics dot mq dot edu dot au
Vrana: your comment makes no sense. If "NANC" is converted to 0, then 0
< 0 would be FALSE, not true.
Compare these expressions:
"NANC" < 0 result TRUE
"NANC" < "0" result FALSE
0 < 0 result FALSE
So it seems it is neither converting "NANC" to an integer 0, nor 0 to a
string "0". What actually is going on? The documentation should clarify
this.
------------------------------------------------------------------------
[2004-01-07 13:20:58] ivo at benetech dot org
It also print 0 as expected.
if( (int) "NANC" < 0)
also evaluates as expected.
------------------------------------------------------------------------
[2004-01-07 05:53:18] [EMAIL PROTECTED]
"NANC" is converted to 0 for comparison. It works for me as expected.
What is printed by the code <?php echo intval("NANC"); ?> on your
system?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/26821
--
Edit this bug report at http://bugs.php.net/?id=26821&edit=1