Voting

Please answer this simple SPAM challenge: max(three, nine)?
(Example: nine)

The Note You're Voting On

ivijan dot stefan at gmail dot com
10 months ago
If you use "AND" and "OR", you'll eventually get tripped up by something like this:

<?php
$this_one
= true;
$that = false;
$truthiness = $this_one and $that;
?>

Want to guess what $truthiness equals?

If you said "false"  ...it's wrong!

"$truthiness" above has the value "true". Why?  "=" has a higher precedence than "and". The addition of parentheses to show the implicit order makes this clearer:

<?php
($truthiness = $this_one) and $that;
?>

If you used "&&" instead of and in the first code example, it would work as expected and be "false".

This also works to get the correct value, as parentheses have higher precedence than "=":

<?php
$truthiness
= ($this_one and $that);
?>

<< Back to user notes page

To Top