Skip to content

Stdlib: ob_start() callback — output buffer filter handler (ext/standard/output.c parity) #3623

Description

@PurHur

Category

stdlib

Problem

ob_start() rejects any arguments with LogicException (ext/standard/ob_start.php). Zend supports an optional callback (and chunk size / erase flags) that can transform or discard buffer contents on flush.

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "ob_start(fn(\$b,\$p)=>strtoupper(\$b)); echo \"hi\"; echo ob_get_clean();" 
php bin/vm.php -r "ob_start(fn(\$b,\$p)=>strtoupper(\$b)); echo \"hi\"; echo ob_get_clean();"
'
Runtime Output
Zend HI
VM LogicException: ob_start() callback arguments not supported in this compiler build

Scope (this repo)

Area Files
VM VM\OutputBuffer, ext/standard/ob_start.php — remove arity guard; invoke callback with PHP_OUTPUT_HANDLER_* phases
JIT ext/standard/JitObStart.php — phase 2 after VM
Tests test/compliance/cases/stdlib/ob_start_callback.phpt
Matrix script/capability-matrix.php

Done when

  • Repro prints HI on bin/vm.php
  • Closure and [$obj, 'method'] callables work on VM
  • Optional $chunk_size / $flags match Zend for at least default + PHP_OUTPUT_HANDLER_CLEANABLE
  • ./script/ci-fast.sh --filter ob_start_callback green
  • JIT/AOT tracked as follow-up issue if still VM-only

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 May 30, 2026
  2. PurHur commented on Jul 11, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jul 11, 2026

    @PurHur
    OwnerAuthor

    Merged via #17842.

    Fix: ob_start() accepts closure/callable handlers; OutputBuffer stores ClosureState or Variable callbacks and applies them on ob_get_clean()/flush. Handler metadata reports CLOSURE::__INVOKE like Zend.

    Verification:

    • php bin/vm.php test/repro/maintainer_gap_ob_start_callback.php → HI
    • vendor/bin/phpunit --filter ob_start_callback → OK (2 tests)
    • vendor/bin/phpunit --filter "ObStart|ob_start|ob_get_clean|ob_get_status|ob_flush" → OK (14 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