Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to create a static property that is static for the derived class, and not for all classes that derive from it?
    text
    copied!<p>I am trying to implement something like this:</p> <pre><code>$child1_instance1 = new \aae\web\ChildOne(); $child1_instance2 = new \aae\web\ChildOne(); $child2_instance1 = new \aae\web\ChildTwo(); $child2_instance2 = new \aae\web\ChildTwo(); // setting the static variable for the first instance of each derived class $child1_instance1-&gt;set('this should only be displayed by instances of Child 1'); $child2_instance1-&gt;set('this should only be displayed by instances of Child 2'); // echoing the static variable through the second instance of each drived class echo $child1_instance2-&gt;get(); echo $child2_instance2-&gt;get(); //desired output: this should only be displayed by instances of Child 1 this should only be displayed by instances of Child 2 // actual output: this should only be displayed by instances of Child 2 this should only be displayed by instances of Child 2 </code></pre> <p>with a class structure similar to this: (I know this doesn't work.)</p> <pre><code>abstract class ParentClass { protected static $_magical_static_propperty; public function set($value) { static::$_magical_static_propperty = $value; } public function get() { return static::$_magical_static_propperty; } } class ChildOne extends ParentClass { } class ChildTwo extends ParentClass { } </code></pre> <p>How do I create static variables for each child class that are not shared across siblings?</p> <p>The reason I would like to be able to do this is to be able to keep track of an event that should only happen once for each derived class, without having the client who is deriving from my parent class have to worry about the implementation of said tracking functionality. The client should be able to check though, if said event has happend.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload