class Category {
private $id, $name;
private static $objectCount = 0; // declare a static property
public function __construct($id, $name) {
$this->id = $id;
$this->name = $name;
self::$objectCount++; // update the static property
}
// A public method that gets the static property
public static function getObjectCount(){
return self::$objectCount;
}
// The rest of the methods for the Category class
}
$guitars = new Category(1, 'Guitars');
$basses = new Category(2, 'Basses');
echo("<p> Object count: " . Category::getObjectCount() . "</p>); // 2
$drums = new Category(3, 'Drums');
echo("<p> Object count: " . Category::getObjectCount() . "</p>); // 3