From def1ab1e60045d823b7e9b84bf6fece38b2302c6 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 8 Apr 2011 10:02:07 +0000 Subject: [PATCH] - Fixed bug #54358 (Closure, use and reference) - Fixed bug #54039 (use() of static variables in lambda functions can break staticness) --- NEWS | 3 +++ Zend/tests/bug54039.phpt | 58 ++++++++++++++++++++++++++++++++++++++++ Zend/tests/bug54358.phpt | 39 +++++++++++++++++++++++++++ Zend/zend_closures.c | 1 + 4 files changed, 101 insertions(+) create mode 100644 Zend/tests/bug54039.phpt create mode 100644 Zend/tests/bug54358.phpt diff --git a/NEWS b/NEWS index 801611684f..36831c81d8 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ PHP NEWS (Tony, Dmitry) . Fixed bug #54372 (Crash accessing global object itself returned from its __get() handle). (Dmitry) + . Fixed bug #54358 (Closure, use and reference). (Dmitry) + . Fixed bug #54039 (use() of static variables in lambda functions can break + staticness). (Dmitry) . Fixed bug #54262 (Crash when assigning value to a dimension in a non-array). (Dmitry) diff --git a/Zend/tests/bug54039.phpt b/Zend/tests/bug54039.phpt new file mode 100644 index 0000000000..ccdfe94305 --- /dev/null +++ b/Zend/tests/bug54039.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #54039 (use() of static variables in lambda functions can break staticness) +--FILE-- +call($function = 'md5'); +}; + +$closure(); + +var_dump($function); + +$closure = function() use ($asserter, $function) { + $asserter->call($function); +}; + +$closure(); + +var_dump($function); + +$closure = function() use ($asserter, $function) { + $asserter->call($function); +}; + +$closure(); + +var_dump($function); +?> +--EXPECT-- +string(3) "md5" +string(3) "md5" +string(3) "md5" diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index d460416e6c..fa26f6efaa 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -347,6 +347,7 @@ static int zval_copy_static_var(zval **p TSRMLS_DC, int num_args, va_list args, } else if (Z_ISREF_PP(p)) { ALLOC_INIT_ZVAL(tmp); *tmp = **p; + zval_copy_ctor(tmp); Z_SET_REFCOUNT_P(tmp, 0); Z_UNSET_ISREF_P(tmp); } else { -- 2.40.0