note 17675 deleted from function.usort by jimw
| From: | jimw@php.net | Date: | Fri, 21 Dec 2001 00:50:23 +0000 |
| Subject: | note 17675 deleted from function.usort by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23702@lists.php.net to get a copy of this message | ||
I am using PHP 4.0.4 and could not get example #3 for usort to work, nor could I understand the
syntax, i.e. uasort($a, array ("TestObj", "cmp_obj"));
At http://www.zend.com/zend/list_change_4.php, I
found a relevant change in PHP 4:
"Allow all functions that receive user-defined function callbacks to accept an array that
contains an object and a method name, in place of a function name, e.g. usort($array, array($obj,
"ObjSort")) (Zeev, Zend Engine)"
So, the function must be passed an array containing and object and a method NAME - therefore, this
corrects the example:
uasort($a, array ($a[0], "cmp_obj"));
Note that the class does not work:
uasort($a, array ($TestObj, "cmp_obj"));
It seems to want an instance of the class.