diff options
author | Dmitry Stogov <dmitry@php.net> | 2011-02-14 10:52:16 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2011-02-14 10:52:16 +0000 |
commit | 64351b7addc5bdb9012c8c1b63c47d54fcb2a86d (patch) | |
tree | ed98ac3d3c88808c81c5e5308c7ac3765bd167c9 /Zend/zend_variables.c | |
parent | 409c5a9c7bf0d0175d7682cde7e98a9ea2c5b5e9 (diff) | |
download | php-git-64351b7addc5bdb9012c8c1b63c47d54fcb2a86d.tar.gz |
Fixed Bug #53958 (Closures can't 'use' shared variables by value and by reference)
Diffstat (limited to 'Zend/zend_variables.c')
-rw-r--r-- | Zend/zend_variables.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c index 302ccb8c8c..77d42bc5c4 100644 --- a/Zend/zend_variables.c +++ b/Zend/zend_variables.c @@ -192,6 +192,7 @@ ZEND_API int zval_copy_static_var(zval **p TSRMLS_DC, int num_args, va_list args { HashTable *target = va_arg(args, HashTable*); zend_bool is_ref; + zval *tmp; if (Z_TYPE_PP(p) & (IS_LEXICAL_VAR|IS_LEXICAL_REF)) { is_ref = Z_TYPE_PP(p) & IS_LEXICAL_REF; @@ -200,26 +201,32 @@ ZEND_API int zval_copy_static_var(zval **p TSRMLS_DC, int num_args, va_list args zend_rebuild_symbol_table(TSRMLS_C); } if (zend_hash_quick_find(EG(active_symbol_table), key->arKey, key->nKeyLength, key->h, (void **) &p) == FAILURE) { - if (is_ref) { - zval *tmp; - + if (is_ref) { ALLOC_INIT_ZVAL(tmp); Z_SET_ISREF_P(tmp); zend_hash_quick_add(EG(active_symbol_table), key->arKey, key->nKeyLength, key->h, &tmp, sizeof(zval*), (void**)&p); } else { - p = &EG(uninitialized_zval_ptr); + tmp = EG(uninitialized_zval_ptr); zend_error(E_NOTICE,"Undefined variable: %s", key->arKey); } } else { if (is_ref) { SEPARATE_ZVAL_TO_MAKE_IS_REF(p); + tmp = *p; } else if (Z_ISREF_PP(p)) { - SEPARATE_ZVAL(p); + ALLOC_INIT_ZVAL(tmp); + ZVAL_COPY_VALUE(tmp, *p); + Z_SET_REFCOUNT_P(tmp, 0); + Z_UNSET_ISREF_P(tmp); + } else { + tmp = *p; } } + } else { + tmp = *p; } - if (zend_hash_quick_add(target, key->arKey, key->nKeyLength, key->h, p, sizeof(zval*), NULL) == SUCCESS) { - Z_ADDREF_PP(p); + if (zend_hash_quick_add(target, key->arKey, key->nKeyLength, key->h, &tmp, sizeof(zval*), NULL) == SUCCESS) { + Z_ADDREF_P(tmp); } return ZEND_HASH_APPLY_KEEP; } |