Countable Interface
The Countable interface is a native built-in interface that allows objects to be counted using the count() function.
By implementing the Countable interface, a class defines custom logic for determining its count.
<?php
class Collection implements Countable
{
private $list = [];
public function add($tusk) {
$this->list[] = $tusk;
}
public function count()
{
return $this->count;
}
}
$count = new Counter;
$count->inc();
$count->inc();
print count($count).PHP_EOL;
?>