note 126969 added to language.operators.precedence

From: Date: Mon, 04 Apr 2022 19:22:20 +0000
Subject: note 126969 added to language.operators.precedence
Groups: php.notes 
Request: Send a blank email to php-notes+get-218127@lists.php.net to get a copy of this message
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. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 86.121.92.80) ---- Manual Page -- https://php.net/manual/en/language.operators.precedence.php Edit -- https://main.php.net/note/edit/126969 Del: integrated -- https://main.php.net/note/delete/126969/integrated Del: useless -- https://main.php.net/note/delete/126969/useless Del: bad code -- https://main.php.net/note/delete/126969/bad+code Del: spam -- https://main.php.net/note/delete/126969/spam Del: non-english -- https://main.php.net/note/delete/126969/non-english Del: in docs -- https://main.php.net/note/delete/126969/in+docs Del: other reasons-- https://main.php.net/note/delete/126969 Reject -- https://main.php.net/note/reject/126969 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218127) next »