3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test() { $orderedids=array(7, 9, 5, 3); $tags=array( new Tag(3), new Tag(7), new Tag(5), new Tag(9) ); $flipped=array_flip($orderedids); $sorter=new stdClass(); $sorter->flipped=$flipped; $sorter->sfunct=function($tag1, $tag2) { if ($this->flipped[$tag1->id]<$this->flipped[$tag2->id]) return -1; else if ($this->flipped[$tag1->id]==$this->flipped[$tag2->id]) return 0; else return 1; }; return usort($tags, array($sorter->sfunct)); } class Tag { public $id; function __construct($id) { $this->id=$id; } } $rtags=test(); foreach ($rtags as $tag) echo $tag->id." ";
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: usort(): Argument #2 ($callback) must be a valid callback, array callback must have exactly two members in /in/kW5N1:23 Stack trace: #0 /in/kW5N1(23): usort(Array, Array) #1 /in/kW5N1(34): test() #2 {main} thrown in /in/kW5N1 on line 23
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: usort(): Argument #2 ($callback) must be a valid callback, array must have exactly two members in /in/kW5N1:23 Stack trace: #0 /in/kW5N1(23): usort(Array, Array) #1 /in/kW5N1(34): test() #2 {main} thrown in /in/kW5N1 on line 23
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: usort() expects parameter 2 to be a valid callback, array must have exactly two members in /in/kW5N1 on line 23 Warning: Invalid argument supplied for foreach() in /in/kW5N1 on line 36

preferences:
166.12 ms | 403 KiB | 222 Q