php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42271 extract EXTR_REFS and/or references
Submitted: 2007-08-11 09:29 UTC Modified: 2007-08-15 08:13 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: rodji at tut dot by Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.3 OS: Win32 XP sp2.2600
Private report: No CVE-ID: None
 [2007-08-11 09:29 UTC] rodji at tut dot by
Description:
------------
Tested on:
Apache/1.3.33 (Win32)
PHP/4.4.7 and 5.2.3

trouble with references in functions

Reproduce code:
---------------
function args_select($args, $args_list, $def_val) {
	$r = array();
	foreach ($args_list as $key) {
		if (array_key_exists($key, $args)){
			$r[$key] = $args[$key];
		}else{
			$r[$key] = $def_val;	//equal $r[$key] =& $def_val   why???
			//$r[$key] = (string)$def_val;	//solution#1
		}
	}
	return $r;
}

$argums = array('action'=>'edit', 'id'=>1);
$select = array('action','to_do','back');

//debug_zval_dump(args_select($argums, $select, ''));

extract(args_select($argums, $select, ''), EXTR_OVERWRITE | EXTR_REFS);
//solution#2   why???
/*$m = args_select($argums, $select, '');
//OR //$m =& args_select($argums, $select, '');
extract($m, EXTR_OVERWRITE | EXTR_REFS);
*/

$to_do = 'new';
debug_zval_dump (&$back);
?>

Expected result:
----------------
&string(0) "" refcount(2)

Actual result:
--------------
&string(3) "new" refcount(3)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-11 22:32 UTC] jani@php.net
Can you provide some simpler example which makes a bit more sense..?
 [2007-08-11 23:58 UTC] rodji at tut dot by
Reproduce code:
---------------
function /*&*/f($val) {	//eq    &f
	$r['a'] = $val;	//equal =&
	$r['b'] = $val;	//equal =&
	return $r;
}

//debug_zval_dump(f('old'));

extract(f('old_value'), EXTR_REFS);
//$t =& f('old_value'); extract($t, EXTR_REFS); unset($t);

$a = 'new_value';
debug_zval_dump (&$b);

Expected result:
----------------
&string(9) "old_value" refcount(2)

Actual result:
--------------
&string(9) "new_value" refcount(3)
 [2007-08-15 08:13 UTC] jani@php.net
You extract $a and $b which both reference the same value so if you change either both change. No bug here -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 07:01:30 2024 UTC