[PHP-DOC] #26821 [Bgs]: if(NANC 0) - always evaluates TRUE

2004-01-09 Thread ivo at benetech dot org
 ID:   26821
 User updated by:  ivo at benetech dot org
 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:

 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.


Previous Comments:


[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  0result 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?



[2004-01-06 18:08:12] ivo at benetech dot org

Documentation needs to be more explicit about php being strongly
typed.

http://www.php.net/manual/en/language.types.type-juggling.php

or

http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion



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=26821edit=1


[PHP-DOC] #26821 [Bgs]: if(NANC 0) - always evaluates TRUE

2004-01-09 Thread sp
 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)$var0)
{
   // 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  0result 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=26821edit=1


[PHP-DOC] #26821 [Bgs]: if(NANC 0) - always evaluates TRUE

2004-01-06 Thread ivo at benetech dot org
 ID:   26821
 User updated by:  ivo at benetech dot org
 Reported By:  ivo at benetech dot org
 Status:   Bogus
-Bug Type: Scripting Engine problem
+Bug Type: Documentation problem
 Operating System: Linux / RH 7.3
 PHP Version:  4.3.4
 New Comment:

Documentation needs to be more explicit about php being strongly
typed.

http://www.php.net/manual/en/language.types.type-juggling.php

or

http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion


Previous Comments:


[2004-01-06 17:23:58] [EMAIL PROTECTED]

RTFM:

http://www.php.net/manual/en/types.comparisons.php

(never ever compare different types like that)




[2004-01-06 16:28:47] ivo at benetech dot org

Description:

The statement...

if(NANC  0)

...always evaluates TRUE.

Reproduce code:
---
if(NANC  0)
{
   print(should not happen...but does\n);
}
else
{
   print(should happen...but doesnt\n);
}

Expected result:

echoed to the console:

should happen...but doesnt

Actual result:
--
echoed to the console:

should not happen...but does





-- 
Edit this bug report at http://bugs.php.net/?id=26821edit=1