*/ class SplPriorityQueue extends \SplPriorityQueue { /** * Seed used to ensure queue order for items of the same priority. */ protected int $serial = PHP_INT_MAX; /** * Insert a value with a given priority. * * Utilizes {@var to $serial} ensure that values of equal priority are * emitted in the same order in which they are inserted. * * @param TValue $value * @param TPriority $priority */ #[ReturnTypeWillChange] public function insert(mixed $value, mixed $priority): bool { return parent::insert($value, [$priority, $this->serial--]); } /** * Serialize to an array. * * Array will be priority => data pairs * * @return list */ public function toArray(): array { $array = []; foreach (clone $this as $item) { $array[] = $item; } return $array; } }