NYCPHP Meetup

NYPHP.org

[nycphp-talk] if statement expression evaluation question

Cliff Hirsch cliff at pinestream.com
Sat Dec 10 16:02:41 EST 2005


I have been looking through the PHP manual for a definitive answer
regarding expression evaluation in an if statement, specifically
regarding the following:

$array = array('a' => 'alpha', 'b' => 'beta', 'c' => 'charlie');
if (isset($array['d']) && ($array['d'] === 'delta'))
  echo 'Its a wonderful life';

This is ok, but the following will generate a parse error:

if (($array['d'] === 'delta') && isset($array['d'])) 

Obviously the first example doesn't evaluate the 2nd expression,
eliminating the non-existent key parsing error. My question is, can I
rely on this? Is the precedence and abortion of the balance of the if
expression guaranteed in this and future releases of PHP?

Cliff Hirsch




More information about the talk mailing list