Skip to content

[8.6] Fix array_map() optimization not resolving the class name of a static FCC - #24244

Merged
arnaud-lb merged 2 commits into
php:PHP-8.6from
claudiodekker:array-map-fix
Oct 14, 2026
Merged

arnaud-lb merged 2 commits into
php:PHP-8.6from
claudiodekker:array-map-fix

Conversation

@claudiodekker

Copy link
Copy Markdown
Contributor

When array_map() is compiled into a loop, the class name of a static first-class callable is compiled as an expression. That gives the name as written, without resolving it against the current namespace or use imports, so the call fails with "Class not found" at runtime:

<?php
namespace Foo {
    class Bar {
        public static function double(int $x): int { return $x * 2; }
    }
}

namespace {
    use Foo\Bar;

    var_dump(array_map(Bar::double(...), [1]));
    // PHP 8.5: array(1) { [0]=> int(2) }
    // PHP 8.6.0RC3: Uncaught Error: Class "Bar" not found
}

Only fully qualified names work. Inside a namespace the bug shows only with \array_map(), because an unqualified array_map() there isn't optimized. self, parent and static are not affected.

This was introduced in 40a8468 (GH-23254), which started evaluating the class name once before the loop. Bisected between RC3 and the point where PHP-8.6 branched from PHP-8.5.

The fix resolves a literal class name with zend_resolve_class_name_ast() before the loop body is compiled, the same way zend_compile_class_ref() does for a regular static call. self, parent, static and dynamic class expressions still take the existing path.

The new test covers imported, aliased, namespace\-relative and fully qualified names in the global namespace, a namespace-relative name under \array_map(), and self, parent and static inside a class.

Tested with make test TESTS="Zend/tests ext/opcache/tests ext/standard/tests/array" on --enable-debug and --enable-debug --enable-zts builds, with opcache off and on. The new test fails without the fix and passes with it.

@claudiodekker claudiodekker reopened this Oct 10, 2026
@claudiodekker
claudiodekker changed the base branch from master to PHP-8.6 October 10, 2026 17:01
@claudiodekker claudiodekker changed the title Fix array_map() optimization not resolving the class name of a static FCC [8.6] Fix array_map() optimization not resolving the class name of a static FCC Oct 11, 2026
@ndossche
ndossche requested a review from arnaud-lb October 11, 2026 19:55
@arnaud-lb
arnaud-lb merged commit d11cbf8 into php:PHP-8.6 Oct 14, 2026
18 checks passed
arnaud-lb added a commit that referenced this pull request Oct 14, 2026
* PHP-8.6:
  Fix array_map() optimization not resolving the class name of a static FCC (#24244)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

@claudiodekker
claudiodekker deleted the array-map-fix branch October 14, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants