Fixed bugs #44181 & #44182 (extract() and references)

(robin_fernandes at uk dot ibm dot com)
This commit is contained in:
Arnaud Le Blanc 2008-11-26 00:59:13 +00:00
parent 42df01cf6e
commit 1064f9721b
3 changed files with 29 additions and 8 deletions

View File

@ -1461,18 +1461,13 @@ PHP_FUNCTION(extract)
if (extract_refs) {
zval **orig_var;
SEPARATE_ZVAL_TO_MAKE_IS_REF(entry);
zval_add_ref(entry);
if (zend_u_hash_find(EG(active_symbol_table), Z_TYPE(final_name), Z_UNIVAL(final_name), Z_UNILEN(final_name) + 1, (void **) &orig_var) == SUCCESS) {
SEPARATE_ZVAL_TO_MAKE_IS_REF(entry);
zval_add_ref(entry);
zval_ptr_dtor(orig_var);
*orig_var = *entry;
} else {
if (Z_REFCOUNT_P(var_array) > 1 || *entry == EG(uninitialized_zval_ptr)) {
SEPARATE_ZVAL_TO_MAKE_IS_REF(entry);
} else {
Z_SET_ISREF_PP(entry);
}
zval_add_ref(entry);
zend_u_hash_update(EG(active_symbol_table), Z_TYPE(final_name), Z_UNIVAL(final_name), Z_UNILEN(final_name) + 1, (void **) entry, sizeof(zval *), NULL);
}
} else {

View File

@ -0,0 +1,13 @@
--TEST--
Test extract() function - ensure EXTR_REFS doesn't mess with isRef flag on COW references to array elements.
--FILE--
<?php
$a = array('foo' => 'original.foo');
$nonref = $a['foo'];
$ref = &$a;
extract($a, EXTR_REFS);
$a['foo'] = 'changed.foo';
var_dump($nonref);
?>
--EXPECTF--
%unicode|string%(12) "original.foo"

View File

@ -0,0 +1,13 @@
--TEST--
Test extract() function - ensure EXTR_REFS works when array is referenced and keys clash with variables in current scope.
--FILE--
<?php
$a = array('foo' => 'original.foo');
$ref = &$a;
$foo = 'test';
extract($a, EXTR_OVERWRITE|EXTR_REFS);
$foo = 'changed.foo';
var_dump($a['foo']);
?>
--EXPECTF--
%unicode|string%(11) "changed.foo"