#22847 [NEW]: Reference don't work in sort callbacks

From: Date: Mon, 24 Mar 2003 12:19:35 +0000
Subject: #22847 [NEW]: Reference don't work in sort callbacks
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-36285@lists.php.net to get a copy of this message
From:             jparneodo at yahoo dot fr
Operating system: RH7.2
PHP version:      4.3.0
PHP Bug Type:     Arrays related
Bug description:  Reference don't work in sort callbacks

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

-- 
Edit bug report at http://bugs.php.net/?id=22847&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22847&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22847&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22847&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22847&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22847&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22847&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22847&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22847&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22847&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22847&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22847&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22847&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22847&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22847&r=gnused



Thread (6 messages)

« previous php.bugs (#36285) next »