Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare

From: Date: Mon, 19 Nov 2001 08:42:05 +0000
Subject: Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare
References: 1  Groups: php.dev php.doc 
Request: Send a blank email to php-dev+get-70869@lists.php.net to get a copy of this message
ID: 14104 User updated by: ernst@baschny.de Reported By: ernst@baschny.de Status: Open Old Bug Type: Arrays related Bug Type: Documentation problem Operating System: Linux RedHat 7.2 PHP Version: 4.0.6 New Comment: Well, in a different context (call_user_func) I found out that it is indeed possible, but not documented. To pass a reference to a function inside a Class to a u.*sort Function, pass it as an array with two elements (the class name and the function name). For the example above, this does it: uasort($a, array("TestObj", "cmp_obj")); Undocumented. So this bug is now a documentation bug. :) Previous Comments: ------------------------------------------------------------------------ [2001-11-19 03:34:34] ernst@baschny.de If I have a static function inside a class that does the comparasion of two objects, I haven't found a way of passing a reference to it in uasort (u.*sort). I tried "Classname::function", also "Classname->function". If the function doesn't exists, not even an error is produced, so its very difficult to debug such things. Heres an example of what doesn't work: class TestObj { var $name; function TestObj($name) { $this->name = $name; } /* This is the static comparing function: */ function cmp_obj($a, $b) { $al = strtolower($a->name); $bl = strtolower($b->name); if ($al == $bl) return 0; return ($al > $bl) ? +1 : -1; } } $a[] = new TestObj("b"); $a[] = new TestObj("a"); $a[] = new TestObj("d"); uasort($a, "TestObj::cmp_obj"); printf("<pre>\n"); print_r($a); printf("</pre>\n"); -> Result: NOT SORTED. ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14104&edit=1

« previous php.dev (#70869) next »