PHP: Assign and use a variable in "if" with "&&"

raw

phork0.txt

<cweiske>       Hi. Why do I get a PHP notice when I define a variable and then use it in the second part of a "&&"?
<cweiske>       $b = 2 && $b;
<cweiske>       PHP Notice:  Undefined variable: b in php shell code on line 1
<cweiske>       afterwards it is defined
<Derick>        cweiske: this is a typical "undefined behaviour" case. Doesn't work in C as you expect either.
<cweiske>       (my actual code was: if ($client = get_client() && $client->is_active)
Christian Weiske Christian Weiske
owner

History