Re: assignment operator works for comparison??
| From: | Yasuo Ohgaki | Date: | Wed, 11 Apr 2001 02:03:49 +0000 |
| Subject: | Re: assignment operator works for comparison?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48106@lists.php.net to get a copy of this message | ||
> if($shiny = 0)
This line is the same as
if ((shiny = 0) == TRUE)
It's common error with PHP and C.
You could make use of this like
if ($fp = fopen($filename,'r'))
since this is the same as
if (($fp = fopen($filename,'r')) == TRUE)
code after this line is executed when fopen() success to open file.
Regards,
--
Yasuo Ohgaki
""Dan"" <iridium77@hotmail.com> wrote in message
news:9avrti$olc$1@toye.p.sourceforge.net...
> This confused me for awhile, because the single equal sign seemed to work
> for comparison, but created inexplicable errors in my programs. It seems
> strange to me that a successful variable value assignment does not return
> true.
>
> example:
>
> <?
>
> $shiny = 1;
> if($shiny = 0){ echo("This wont print"); }
> echo( $shiny ); //this will return 0
>
> ?>
>
> --Dan
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>