note 126969 deleted from language.operators.precedence by cmb

From: Date: Mon, 04 Apr 2022 20:02:55 +0000
Subject: note 126969 deleted from language.operators.precedence by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218129@lists.php.net to get a copy of this message
Note Submitter: joe at joe dot joe ---- Contributor noone mentions ~~~ if($a=5&&$a==5){ echo '5'; } else { echo 'not 5'; } //echos not 5 You'll get a Notice: Undefined variable: a; This happens because the expression is treated as ($a=5&&($a==5)) In this case $a was undefined. ~~~ The correct explanation is in fact that the condition is treated like ( $a = (5 && $a == 5) ) given the fact that = evaluates the right side first, and in this case the right side tries to access $a before it is defined. The same contributor notes that ( ($a = 5) && $a==5 ) works which is true but just because we now have forced the attribution to stop at the closed parenthesis.

« previous php.notes (#218129) next »