PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
foo() is called with true and echos true but returns !true which is false
so bar() is evaluated and passed false (returned from foo()) and echos !false which is true but returns false
the original echo expression evaluates to false so false is echoed
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
pickle wrote:If it can't be evaluated, it's unknowable.
Well, I didn't think that meant I couldn't evaluate it in my brain. Or was that your point?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
if true = "true" or "true", the answer must be false. (true true false)
foo(true) matches false, so returns true
bar(true) does not match, so returns true
so if the variable $v does not match either, then the answer must be false
Edit: realized the mistake. Was a late night
Last edited by Weiry on Wed Mar 03, 2010 7:14 pm, edited 2 times in total.
OK, I see there are no posts for the last 5 days, so I will consider this "challenge" closed.
If you take a look at the AND/OR PHP manual page you'll see that:
// "||" has a greater precedence than "or"
...
// "&&" has a greater precedence than "and"
...
while it's true the manual page doesn't explicitly explains that AND/OR operators have lower precedence than the assignment operator "=". It's clearly explained in the Operator Precedence, but it's not so in the Logical Operators page (not to mention the Bulgarian version of Logical operators page, where some very important notices are missing )
That's why I decided to examine your PHP knowledge
So, first foo($v) is executed, its return value is assigned to $v and then bar($v) is executed with the new value of $v, and finally the OR operator is evaluated and its return value is again assigned to $v.
There are 10 types of people in this world, those who understand binary and those who don't