Hi:
Was just thinking about some details of the traits implementation.
From my perspective, static variables in methods should work like the method would have been actually implemented in the class using the traits. Thus, static variables should be independent for the different traits usages.
Any thoughts on that?
Below, I attached the relevant test case.
Best regards
Stefan
--TEST--
Statics work like expected for language-based copy'n'paste. No link between methods from the same trait.
--FILE--
<?php
error_reporting(E_ALL);
trait Counter {
public function inc() {
static $c = 0;
$c = $c + 1;
echo "$c\n";
}
}
class C1 {
use Counter;
}
class C2 {
use Counter;
}
$o = new C1();
$o->inc();
$o->inc();
$p = new C2();
$p->inc();
$p->inc();
?>
--EXPECTF--
1
2
1
2
Hi:
Was just thinking about some details of the traits implementation.
From my perspective, static variables in methods should work like the method would have been actually implemented in the class using the traits. Thus, static variables should be independent for the different traits usages.
Any thoughts on that?
i agree. the mantra is traits are engine level automated copy&paste.
regards,
Lukas Kahwe Smith
mls@pooteeweet.org