3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * sort() triggers type-conversion notice * @link https://bugs.php.net/bug.php?id=64580 */ error_reporting(~0); $errors = 0; $objects = 0; $subject = array(3, 3, 2, 3, 3, 2, 2, 3, 3, 1, 1, obj(1), 1, obj(1.2), 2, obj(2), 2, 2, 2, 2, obj(2.1), 1, 0, 0); set_error_handler('suppress_and_count'); sort($subject); restore_error_handler(); printf("sort caused %d error(s) in an array of %d member(s) of which %d are object(s).\n", $errors, count($subject), $objects); echo 'sort()-result: ', implode(', ', array_map('tostring', $subject)); // --------------- functions ----------------- // function obj($prop) { global $objects; $objects++; return (object) array('prop' => $prop); } function arr($val) { return array($val); } function tostring($val) { if (is_object($val)) { $val = sprintf('obj(%s)', $val->prop); } if (is_array($val)) { $val = '[' . implode(',', $val) . ']'; } return $val; } function suppress_and_count() { global $errors; $errors++; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
sort caused 15 error(s) in an array of 24 member(s) of which 4 are object(s). sort()-result: 0, 0, 1, 1, obj(1), 1, obj(1.2), obj(2), obj(2.1), 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3
Output for 7.0.0 - 7.0.5, 7.0.7 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
sort caused 9 error(s) in an array of 24 member(s) of which 4 are object(s). sort()-result: 0, 0, 1, 1, obj(1), obj(1.2), obj(2), obj(2.1), 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3
Output for 7.0.6

Process exited with code 137.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
sort caused 43 error(s) in an array of 24 member(s) of which 4 are object(s). sort()-result: 0, 0, 1, 1, 1, 1, obj(1), obj(1.2), obj(2), obj(2.1), 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5
sort caused 0 error(s) in an array of 24 member(s) of which 4 are object(s). sort()-result: 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, obj(1), obj(1.2), obj(2), obj(2.1)

preferences:
261.93 ms | 402 KiB | 398 Q