Edit report at https://bugs.php.net/bug.php?id=64580&edit=1
ID: 64580 Updated by: ni...@php.net Reported by: hanskrentel at yahoo dot de Summary: sort() triggers type-conversion notice -Status: Open +Status: Not a bug Type: Bug Package: Arrays related PHP Version: 5.4.13 Block user comment: N Private report: N New Comment: Nothing to do with sort() this is just the usual behavior of the "<" operator. Try doing just "1 < new stdClass" and you'll get the same notice. Previous Comments: ------------------------------------------------------------------------ [2013-04-04 12:43:42] hanskrentel at yahoo dot de Description: ------------ Under specific circumstances the sort() function with the `SORT_REGULAR` sort- flag triggers type-conversion notices even it is documented that no type- conversion is done[1]: > SORT_REGULAR - compare items normally (don't change types) This notice is *only* given if an object value is sorted with an integer or float. The notices for these two cases are as following: > Notice: Object of class stdClass could not be converted to int > Notice: Object of class stdClass could not be converted to double Those errors are triggered in /Zend (lxr search http://goo.gl/Zu7Zl). The sort() function returns TRUE despite the Notice and as far I was able to find out, the sorting is done, so this looks correct to me. Also this error only happens with sorting objects with integers and floats. I also tested against NULL, boolean (TRUE/FALSE), string, array, object and resource and these did not trigger the notice. I would not classify this as documentation bug because these are very specific circumstances which makes me assume that this is not the intended behavior. Something might have been just overlooked for these two cases with `SORT_REGULAR`. It should be said that there are related issues documented in #54980 and #54259 over which I originally stumbled. [1] http://php.net/sort Test script: --------------- <?php $subject = [1, (object) ['prop' => 'value']]; sort($subject); Actual result: -------------- Notice: Object of class stdClass could not be converted to int in [...] on line 3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64580&edit=1