Browse Source
Fixed issue with statics in traits.
Fixed issue with statics in traits.
#Please review this change, I moved the routine which copies statics from the closure code to zend_variables.c #Please also have a look to check whether the TSRMLS_DC is correct, and whether it fits with the rest in zend_variables, because there you are using some macro magic and I am not exactly sure what the reason is for that.experimental/lemon
6 changed files with 105 additions and 39 deletions
-
27Zend/tests/traits/language012.phpt
-
37Zend/tests/traits/language013.phpt
-
37Zend/zend_closures.c
-
5Zend/zend_compile.c
-
37Zend/zend_variables.c
-
1Zend/zend_variables.h
@ -0,0 +1,27 @@ |
|||
--TEST-- |
|||
Statics should work in traits, too. |
|||
--FILE-- |
|||
<?php |
|||
error_reporting(E_ALL); |
|||
|
|||
trait Counter { |
|||
public function inc() { |
|||
static $c = 0; |
|||
$c = $c + 1; |
|||
echo "$c\n"; |
|||
} |
|||
} |
|||
|
|||
|
|||
class C1 { |
|||
use Counter; |
|||
} |
|||
|
|||
$o = new C1(); |
|||
$o->inc(); |
|||
$o->inc(); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
1 |
|||
2 |
|||
@ -0,0 +1,37 @@ |
|||
--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 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue