Skip to content

Commit 2e925f6

Browse files
committed
Fixed bug #55825, and add test script
1 parent 24cbd8f commit 2e925f6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
(Felipe, Laruence)
1313
. Fixed bug #55758 (Digest Authenticate missed in 5.4) . (Laruence)
1414
. Fixed bug #55622 (memory corruption in parse_ini_string). (Pierre)
15+
. Fixed bug #55825 (Missing initial value of static locals in trait methods).
16+
(Laruence)
1517

1618
- Zlib:
1719
. Fixed bug #55544 (ob_gzhandler always conflicts with

Zend/tests/bug55825.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #55825 (Missing initial value of static locals in trait methods)
3+
--FILE--
4+
<?php
5+
trait T1 {
6+
public function inc() {
7+
static $x=1;
8+
echo $x++ . "\n";
9+
}
10+
}
11+
class C { use T1; }
12+
$c1 = new C;
13+
$c1->inc();
14+
$c1->inc();
15+
--EXPECT--
16+
1
17+
2

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3695,7 +3695,7 @@ static void zend_traits_duplicate_function(zend_function *fe, zend_class_entry *
36953695

36963696
ALLOC_HASHTABLE(tmpHash);
36973697
zend_hash_init(tmpHash, zend_hash_num_elements(fe->op_array.static_variables), NULL, ZVAL_PTR_DTOR, 0);
3698-
zend_hash_apply_with_arguments(tmpHash TSRMLS_CC, (apply_func_args_t)zval_copy_static_var, 1, fe->op_array.static_variables);
3698+
zend_hash_apply_with_arguments(fe->op_array.static_variables TSRMLS_CC, (apply_func_args_t)zval_copy_static_var, 1, tmpHash);
36993699

37003700
fe->op_array.static_variables = tmpHash;
37013701
}
@@ -4101,6 +4101,7 @@ static void zend_do_traits_method_binding(zend_class_entry *ce TSRMLS_DC) /* {{{
41014101
zend_hash_graceful_destroy(resulting_table);
41024102
free(resulting_table);
41034103
}
4104+
/* }}} */
41044105

41054106
static zend_class_entry* find_first_definition(zend_class_entry *ce, size_t current_trait, const char* prop_name, int prop_name_length, ulong prop_hash, zend_class_entry *coliding_ce) /* {{{ */
41064107
{

0 commit comments

Comments
 (0)