Skip to content

Instantly share code, notes, and snippets.

@selfawaresoup
Created June 13, 2013 12:58
Show Gist options
  • Save selfawaresoup/5773467 to your computer and use it in GitHub Desktop.
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?
<?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
@janl
Copy link

janl commented Jun 13, 2013

if you understand zvals, it makes all sense :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment