ID: 17180 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Analyzed Bug Type: Scripting Engine problem PHP Version: 4.2.0 New Comment:
This behaviour is capable to confuse the developer and if this is "features" it must be documented in manual. Previous Comments: ------------------------------------------------------------------------ [2002-05-13 18:20:14] [EMAIL PROTECTED] Well, but it's stupid to do something like that. It makes no sense to assign anything to NOT(a variable), so PHP takes care of that by changing the precedence a little in this case. ------------------------------------------------------------------------ [2002-05-13 17:56:54] [EMAIL PROTECTED] Yes, I want ASSIGN value to $a and check assigned value. But parser must say: "parser error", becouse it can not assign value to constant. Please reopen. ------------------------------------------------------------------------ [2002-05-13 17:48:54] [EMAIL PROTECTED] "if (!$a = foo(FALSE))" --> you're assigning the output of foo(FALSE) to $a "if (!$a == foo(FALSE))" --> you're comparing !$a and foo(FALSE) ------------------------------------------------------------------------ [2002-05-13 09:36:32] [EMAIL PROTECTED] Why & How this code will work? <? function foo($flag) { return $flag; } $a=TRUE; echo "if (!\$a = foo(FALSE))) is "; if (!$a = foo(FALSE)) echo "true"; else echo "false"; echo "\n"; var_dump($a); echo "\n"; ?> Output: if (!$a = foo(FALSE))) is true bool(false) http://www.php.net/manual/en/language.operators.php "Operator Precedence" `!` has more precedence than `=` And after `!` we must have boolean constant in left side: FALSE = foo() Explain to me pls that I do not understand P.S. in C & Perl (!$a = foo()) is not valid expression ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17180&edit=1