note 72780 added to function.sort
| From: | joris at mangrove dot nl | Date: | Thu, 01 Feb 2007 13:40:36 +0000 |
| Subject: | note 72780 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122473@lists.php.net to get a copy of this message | ||
Commenting on note http://www.php.net/manual/en/function.sort.php#62311
:
Sorting an array of objects will not always yield the results you desire.
As pointed out correctly in the note above, sort() sorts the array by value of the first member
variable. However, you can not always assume the order of your member variables! You must take into
account your class hierarchy!
By default, PHP places the inherited member variables on top, meaning your first member variable is
NOT the first variable in your class definition!
However, if you use code analyzers or a compile cache, things can be very different. E.g., in
eAccelerator, the inherited member variables are at the end, meaning you get different sort results
with caching on or off.
Conclusion:
Never use sort on arrays with values of a type other than scalar or array.
----
Server IP: 69.147.83.197
Probable Submitter: 82.92.203.24
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/72780
Del: integrated -- https://master.php.net/note/delete/72780/integrated
Del: useless -- https://master.php.net/note/delete/72780/useless
Del: bad code -- https://master.php.net/note/delete/72780/bad+code
Del: spam -- https://master.php.net/note/delete/72780/spam
Del: non-english -- https://master.php.net/note/delete/72780/non-english
Del: in docs -- https://master.php.net/note/delete/72780/in+docs
Del: other reasons-- https://master.php.net/note/delete/72780
Reject -- https://master.php.net/note/reject/72780
Search -- https://master.php.net/manage/user-notes.php