In PHP, count(false) returns 1!

This is because casting a false value as an array (which happens automatically when using count()) returns an array containing a single element with the value false. Fun.

$ php -a
Interactive mode enabled

<?php

var_dump(count(false));
int(1)
var_dump(count(true));
int(1)
var_dump(count(''));
int(1)
var_dump(count(null));
int(0)
var_dump(count((array)false));
int(1)
var_dump((array)false);
array(1) {
  [0]=>
  bool(false)
}

comments: be first!

name
blog (optional)
comment

monthchunks

license

Justinsomnia is licensed under a Creative Commons Attribution 3.0 License.

Please see my Attribution Policy for more information.