SplPriorityQueue is advertised as a prioritized queue. Ideally, as a queue, when adding items of the same priority, the items should retain the same order as how they were registered (FIFO). In PHP the order is unexpected:
<?php
$queue = new SplPriorityQueue();
$queue->insert('1',0);
$queue->insert('2',0);
$queue->insert('3',0);
$queue->insert('4',0);
$queue->insert('5',0);
while($queue->valid()){
var_dump( $queue->current() );
$queue->next();
}
Output:
string(1) "1"
string(1) "5"
string(1) "4"
string(1) "3"
string(1) "2"
- Demo: https://3v4l.org/eNXSo
- Bug Wont Fix: https://bugs.php.net/bug.php?id=53710