Trying to set an array and a count, which are both static members, by referencing them after getting the type of the current class. The intention is to have a global list of all items of a particular type that I have loaded, but I would like them to be split up into the static properties for each particular class. The issue is that I will be inheriting a few classes from a base class, but I want the static property in the ‘child’ class to get appended to.
Here’s what I’m shooting for, give or take:
$Class = get_class($this);
($Class)::$List[($Class)::$Count++] = $this;
In PHP 5.3 and later, you can use late static binding to access overridden static variables. The short version is that you use
staticrather thanselfor the class name when accessing static variables. For example:Keep in mind that if a child class defines a constructor, it must explicitly call the parent’s constructor.