Skip to content

Regression: CallbackFilterIterator(new ArrayIterator(...), fn) nested — ArrayIterator::__invoke (re-#13180, ext/spl/spl_iterators.c) #19771

Description

@PurHur

Category

Regression · php-src-strict · nested new + arrow-fn callback (re-#13180 / #6692)

Problem

new CallbackFilterIterator(new ArrayIterator([1,2,3,4]), fn($v) => $v % 2 === 0) fatals on VM with LogicException: Call to undefined method ArrayIterator::__invoke(). Zend filters to 2,4. Binding the iterator and/or Closure to locals first matches Zend — the nested-new + inline arrow form misbinds the callback (iterator object used as callable) (2026-07-16).

Repro Zend 8.2+ VM (2026-07-16)
new CallbackFilterIterator(new ArrayIterator([1,2,3,4]), fn($v)=>$v%2===0) 2,4 LogicException: Call to undefined method ArrayIterator::__invoke()
$inner=...; $cb=fn...; new CallbackFilterIterator($inner,$cb) 2,4 2,4
string callback "even" 2,4 2,4

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/callback_filter_iterator_arrow_nested.php; php bin/vm.php test/repro/callback_filter_iterator_arrow_nested.php'
<?php
error_reporting(E_ALL);
try {
    $it = new CallbackFilterIterator(new ArrayIterator([1, 2, 3, 4]), fn($v) => $v % 2 === 0);
    echo implode(',', iterator_to_array($it, false)) . "\n";
} catch (Throwable $e) {
    echo get_class($e) . ': ' . $e->getMessage() . "\n";
}

Done when

  • VM prints 2,4 matching Zend; exit 0
  • Locals-bound and string-callback forms stay green
  • Compliance .phpt under test/compliance/cases/spl/
  • php-src-strict; no php-compiler-strict shortcut

Activity

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 machinebugSomething isn't workingenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions