Trait that implements the Countable interface.
Enables count()
function on class.
Trait synopsis
trait CountableTrait
{
use TypeTrait;
// Countable interface implementation.
/**
* Count elements of instance.
* @return int Number of elements.
*/
public function count(): int;
}
Examples
use Phrity\O\Array\CountableTrait;
class MyClass implements Countable
{
use CountableTrait;
public function __construct(array $input)
{
$this->initialize($input);
}
}
$class = new MyClass(['a' => 1, 'b' => 2, 'c' => 3]);
count($class); // => 3
Requirements
PHP
^8.0