|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-24 06:19 UTC] jparneodo at yahoo dot fr
function cmp($a,$b){
global $g;
var_dump($g); // NULL here
if($g[$a]>$g[$b]){
return -1;
}elseif($g[$a]<$g[$b]){
return 1;
}else{
return 0;
}
}
class A {
var $aa=array('B'=>2,'A'=>1,'C'=>3);
function sortme(){
global $g;
$g=&$this->aa;
uksort($g,'cmp');
}
}
$a=new A;
$a->sortme(); // Don't work
$g=&$a->aa;
uksort($g,'cmp'); // Work
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 08:00:02 2025 UTC |
The problem can be replicated with a simpler script: <?php class A { var $b=1; function test() { global $g; $g =& $this->b; } } $n = new A(); $g = "BAR"; $n->test(); var_dump($g); ?> The problem itself appears to be ZE's inability to make a variable imported using global a reference. if $GLOBALS['var_name'] is used the script works correctly