How don't the static properties in traits lose its value when used by classes Although Traits are language assisted Copy/paste? let's consider the following example,
trait Test{
public static $var = 1;
public static function increment(){
self::$var ++;
var_dump(self::$var);
}
}
Test::increment();//2
class Test2{
use Test;
}
var_dump(Test2::$var);//2
Test2::increment();//3
This behaviour is correct in inheritance where the child extends the parent, so the child uses the parent static variables, but according to traits where copy and paste are applied, how does this work and correct?
This is an update to add another reason to the confusion I have, if the static values are reserved to specific contexts like specific class or function, so how do I able to use updated values of static properties from a different context ( the new class). I mean, if the context of trait Test is called for example Context1, and the class Test2 context is called Context2, how do I access the reserved values of the first context in another context? this is against the contexts approach we understand.
Update 3: all of this confusion depends on if the use keyword is importing the trait members in class or copy/paste?