Bug #14104: uasort doesn't work with static functions from inside classes to compare
| From: | ernst at baschny dot de | Date: | Mon, 19 Nov 2001 08:34:35 +0000 |
| Subject: | Bug #14104: uasort doesn't work with static functions from inside classes to compare | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-70866@lists.php.net to get a copy of this message | ||
From: ernst@baschny.de
Operating system: Linux RedHat 7.2
PHP version: 4.0.6
PHP Bug Type: Arrays related
Bug description: uasort doesn't work with static functions from inside classes to compare
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 bug report at: http://bugs.php.net/?id=14104&edit=1