Skip to content

Stdlib: SPL heap structures — SplPriorityQueue / SplMinHeap / SplMaxHeap parity (ext/spl/spl_heap.c) #4387

Closed

Description

@PurHur

Category

stdlib

Problem

SPL heap structures are missing: SplPriorityQueue, SplMinHeap, and SplMaxHeap should match Zend insert/extract ordering, compare semantics, and SplPriorityQueue::setExtractFlags() modes.

Distinct from #3330 (ArrayObject/queue/stack/storage) and #4689 (SplDoublyLinkedList). Registration should go through ext/spl/Module.php once #4769 lands.

php-src reference

Repro

Save as repro_spl_priority_queue.php:

<?php
$pq = new SplPriorityQueue();
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
$pq->insert('low', 1);
$pq->insert('high', 100);
$first = $pq->extract();
$second = $pq->extract();
echo $first['data'], ':', $first['priority'], "\n";
echo $second['data'], ':', $second['priority'], "\n";

$max = new SplMaxHeap();
$max->insert(1);
$max->insert(3);
echo $max->extract(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_spl_priority_queue.php
php bin/vm.php repro_spl_priority_queue.php
'
Runtime First line
Zend high:100
This compiler Class "SplPriorityQueue" not found

Scope (this repo)

Layer Path
Module ext/spl/Module.php (#4769)
VM classes lib/VM/BuiltinClasses.php or ext/spl/SplPriorityQueue.php heap storage
Methods v1 insert, extract, count, isEmpty, top, setExtractFlags, getExtractFlags
Min/Max heap SplMinHeap / SplMaxHeap with default compare
JIT/AOT VM-first v1
Tests test/compliance/cases/stdlib/spl_priority_queue.phpt, spl_max_heap.phpt

Done when

  • Repro prints high:100 then low:1 on VM
  • SplMaxHeap extract order matches Zend (3 before 1)
  • EXTR_DATA, EXTR_PRIORITY, EXTR_BOTH flags behave per php-src for supported subset
  • ./script/ci-fast.sh --filter spl_priority_queue green
  • Capability matrix rows for all three classes

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 2, 2026
  2. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #4387, #6138, #6563)

    Starting with #4387 SplHeap/SplMinHeap/SplMaxHeap/SplPriorityQueue method tables (classes stubbed on master; insert/extract missing). Then #6138 IteratorIterator+Generator rewind, then #6563 socket_create_pair.

  3. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — continuing batch after #6138 merged (#19327). Starting #4387 SplHeap/SplPriorityQueue methods next.

  4. PurHur commented on Jul 15, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #19328.

    Shipped: SplHeap / SplMinHeap / SplMaxHeap / SplPriorityQueue method tables in ext/spl/SplHeapBuiltin.php — insert/extract/top/count/isEmpty/iterator + EXTR_* flags.

    Verification:

    php bin/vm.php test/repro/issue_4387_spl_priority_queue.php
    # high:100
    # low:1
    # 3
    php -d memory_limit=1536M vendor/bin/phpunit --filter "spl_priority_queue|spl_max_heap"
    # OK (4 tests)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions