Date: 11/19/01
- Next message: Derick Rethans: "[PHP-DOC] cvs: phpdoc /en/functions array.xml"
- Previous message: Hartmut Holzgraefe: "[PHP-DOC] cvs: phpdoc / funcindex.xml"
- Next in thread: derick <email protected>: "[PHP-DOC] Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare"
- Maybe reply: derick <email protected>: "[PHP-DOC] Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 14104
User updated by: ernst <email protected>
Reported By: ernst <email protected>
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 <email protected>
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
- Next message: Derick Rethans: "[PHP-DOC] cvs: phpdoc /en/functions array.xml"
- Previous message: Hartmut Holzgraefe: "[PHP-DOC] cvs: phpdoc / funcindex.xml"
- Next in thread: derick <email protected>: "[PHP-DOC] Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare"
- Maybe reply: derick <email protected>: "[PHP-DOC] Bug #14104 Updated: uasort doesn't work with static functions from inside classes to compare"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

