Created
June 13, 2013 12:58
-
-
Save selfawaresoup/5773467 to your computer and use it in GitHub Desktop.
The builtin count() in PHP is so simple, it can't be broken, right?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// All these expressions are (bool)true: | |
count([]) === 0; // Ok, that's expected. | |
count(true) === 1; // Wait, I can count non-arrays? What does this even mean? | |
count(false) === 1; // WTF? | |
count(0) === 1; // yeah, obviously … | |
count("") === 1; // I'm, starting to see a pattern. | |
//Ok, so if I put in any non-array into count() it's going to be 1 because each is one expression, right? | |
count(null) === 0; // http://ragefac.es/100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you understand zvals, it makes all sense :)