I just want to point out that your class has to actually implement the Countable interface, not just define a count method, to be able to use count($object) and get the expected results. I.e. the first example below won't work as expected, the second will. (The normal arrow function accessor ($object->count()) will work fine, but that's not the kewl part :) )
<?php
class CountMe
{
protected $_myCount = 3;
public function count()
{
return $this->_myCount;
}
}
$countable = new CountMe();
echo count($countable); class CountMe implements Countable
{
protected $_myCount = 3;
public function count()
{
return $this->_myCount;
}
}
$countable = new CountMe();
echo count($countable); ?>