class MyClass implements Countable {
public function count() {
return 5;
}
}
$c = new MyClass();
echo $c->count();
echo count($c); //calls $c->count();
We can use count() function for the class instance, when the class implements Countable
interface