PHP Pop Quiz

Someone mentioned to me today that PHP does not crash if you divide by zero. So, I tried it.

Sure enough, <?php var_dump(42/0); ?> throws a warning, but prints bool(false).

So I played around a little bit more and came up with some really pathological mathematical expressions in PHP that don’t do what you think they might.

What do you think these output?

Try to reason out what the value (and type) of the result of each expression might be, then try running it in PHP. After you discover the correct result of an expression (and think you understand why), try the next one.

<?php
var_dump(false/false);
var_dump(false/true);
var_dump(true+false<false^true);
var_dump(pow(false, -true));
var_dump(pow(false, false));
?>

How many did you get?

1 thought on “PHP Pop Quiz”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top