Re: [PHP] = 0 and = 0

2001-10-26 Thread ~~~i LeoNid ~~
On Thu, 25 Oct 2001 02:04:14 -0700 (PDT) impersonator of [EMAIL PROTECTED] (Rasmus Lerdorf) planted I saw in php.general: if(strpos(abcdef,abc)) { ... } and then be confused that the condition appeared not to be met. What they actually should have done was: if(strpos(abcdef,abc)!==false)

[PHP] = 0 and = 0

2001-10-25 Thread Robin Chen
why does ? $qty = 0 ; if ($qty != test) print qty is not test; ? work properly but not the following ? $qty = 0 ; if ($qty != test) print qty is not test; ? Thanks, Robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands,

Re: [PHP] = 0 and = 0

2001-10-25 Thread Vitali Falileev
Hello Robin, Very simple. :) RC ? $qty = 0 ; if ($qty != test) print qty is not test; ? $qty is string, so PHP compares 0 with test char by char. chr(0) isn't equal t. RC ? $qty = 0 ; if ($qty != test) print qty is not test; ? In this case $qty is integer value, so PHP tries to convert test

RE: [PHP] = 0 and = 0

2001-10-25 Thread Matthew Loff
in the 2nd example, the string is casted to int, and the int cast of test is 0. -Original Message- From: Robin Chen [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 25, 2001 4:06 AM To: [EMAIL PROTECTED] Subject: [PHP] = 0 and = 0 why does ? $qty = 0 ; if ($qty != test) print qty

Re: [PHP] = 0 and = 0

2001-10-25 Thread Kodrik
? $qty = 0 ; if ($qty != test) print (qty is not test); ? ? $qty = 0 ; if ($qty != test) printf(qty is not test); ? I just tested those two lines with php 4.0.6 and they both work. There is a difference though. If you set $qty=0; then $qty has no value. But if you set $qty=0, it has a value.

Re: [PHP] = 0 and = 0

2001-10-25 Thread Rasmus Lerdorf
If you set $qty=0; then $qty has no value. Of course it has a value. The value is 0. Quite distinct from not having a value, or in proper terms, not being set. Try this: var_dump($qty); $qty = 0; var_dump($qty); Well, I will save you the trouble, it outputs: NULL int(0) Type

Re: [PHP] = 0 and = 0

2001-10-25 Thread Kodrik
If you set $qty=0; then $qty has no value. Of course it has a value. No it doesn't have a value. PHP interprets 0 as null. A very easy way for you to check: $value=0; if(!$value) printf($value doesn't have a value (it didn't even print 0)br\n); $value=0 if($value) printf($value does

Re: [PHP] = 0 and = 0

2001-10-25 Thread Robin Chen
Thank you, that was it. I needed to test the variable against both an integer and a string, so I ended up using (string) when I need to compare a string. Rest of the time, it's an integer. Robin Rasmus Lerdorf wrote: If you set $qty=0; then $qty has no value. Of course it has a value.

Re: [PHP] = 0 and = 0

2001-10-25 Thread Robin Chen
The integer 0 is equal to False, but not Null. Robin Kodrik wrote: If you set $qty=0; then $qty has no value. Of course it has a value. No it doesn't have a value. PHP interprets 0 as null. A very easy way for you to check: $value=0; if(!$value) printf($value doesn't have

Re: [PHP] = 0 and = 0

2001-10-25 Thread Rasmus Lerdorf
Kodrik, you are picking the wrong person to argue with. ;) If you set $qty=0; then $qty has no value. Of course it has a value. No it doesn't have a value. PHP interprets 0 as null. Completely incorrect. A very easy way for you to check: $value=0; if(!$value) printf($value

Re: [PHP] = 0 and = 0

2001-10-25 Thread Kodrik
You are right, 0 didn't show as a value. But his two lines still don't need typecasting, they both work: http://24.234.52.166 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list

Re: [PHP] = 0 and = 0

2001-10-25 Thread Rasmus Lerdorf
$qty=0; then $qty has no value. Of course it has a value. No it doesn't have a value. PHP interprets 0 as null. A very easy way for you to check: $value=0; if(!$value) printf($value doesn't have a value (it didn't even print 0)br\n); $value=0 if($value) printf

Re: [PHP] = 0 and = 0

2001-10-25 Thread Rasmus Lerdorf
You are right, 0 didn't show as a value. But his two lines still don't need typecasting, they both work: http://24.234.52.166 I don't mean to pick on you, but no, you are wrong. And I am only doing this because so many people get confused on this point and I always see questions related

Re: [PHP] = 0 and = 0

2001-10-25 Thread Kodrik
Check the link I posted. http://24.234.52.166 There is the code I wrote and it's output. The two lines print. You can explain me why tomorrow they print on my server and not yours. Good night But his two lines still don't need typecasting, they both work: http://24.234.52.166 I don't mean

Re: [PHP] = 0 and = 0

2001-10-25 Thread John A. Grant
Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The integer 0 is equal to False, but not Null. Not quite true. 0 evaluates to false. They are not equal. Try this: [...] So be careful and try to think of 0 and false as distinct and

RE: [PHP] = 0 and = 0

2001-10-25 Thread Christoph Starkmann
Hi John! The integer 0 is equal to False, but not Null. Not quite true. 0 evaluates to false. They are not equal. Try this: [...] So be careful and try to think of 0 and false as distinct and separate entities and you will avoid coding mistakes like this. Is this