ID: 17180 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Analyzed Bug Type: Scripting Engine problem PHP Version: 4.2.0 New Comment:
Actually this is a bug, since in PHP manual it's clearly stated that ! operator has a priority over = operator. > 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. In other words - if user makes a mistake and writes illegal code, PHP takes care about that and makes this code work (but in a way different from what developer has expected). Also if you consider any other programming languages, if you write a code which should not compile by language specifications (like the above code in PHP), no compiler will try to "take care" of that. If you insist on that "care", then you definetely have to reflect that in the manual, otherwise it's nothing but a bug. Previous Comments: ------------------------------------------------------------------------ [2002-05-13 18:30:31] [EMAIL PROTECTED] This behaviour is capable to confuse the developer and if this is "features" it must be documented in manual. ------------------------------------------------------------------------ [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