Skip to content

Language: JIT new $class (variable classname) — LogicException resolveClassId (Zend/zend_compile.c) #27156

Closed

Description

@PurHur

Category

Language · php-src-strict · JIT instantiation · pillar 4

Problem

new $class when $class is a runtime string works on Zend and VM (and is a common dynamic-instantiation pattern). JIT aborts in Object_::resolveClassId() with LogicException: JIT only supports constant named classes for class const fetch — the dynamic classname operand is rejected as if it were a class-const fetch.

Verified 2026-08-03 at e0e5e10c9 (Docker Zend 8.2.32):

Repro Zend 8.2.32 VM JIT
$c='stdClass'; echo get_class(new $c) stdClass stdClass LogicException (resolveClassId)
throw new $c('boom') with $c='Exception' Exception:boom Exception:boom same JIT fatal

Related closed work covered $class::CONST (#4095) and $var::class (#4179); this is the complementary new $var path.

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/new_var.php << \"PHP\"
<?php
$class = \"stdClass\";
$o = new $class;
echo get_class($o), \"\n\";
$class2 = \"Exception\";
try { throw new $class2(\"boom\"); } catch (Throwable $e) {
  echo get_class($e), \":\", $e->getMessage(), \"\n\";
}
PHP
php /tmp/new_var.php
php bin/vm.php /tmp/new_var.php
php bin/jit.php /tmp/new_var.php'

Expect stdClass / Exception:boom on all three.

Done when

  • bin/jit.php prints stdClass + Exception:boom (no resolveClassId LogicException)
  • Invalid classname throws Error matching Zend
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 3, 2026
  2. PurHur commented on Aug 3, 2026

    @PurHur
    OwnerAuthor

    claim: Worker lane A — starting this run (JIT new $class / resolveClassId)

  3. PurHur commented on Aug 3, 2026

    @PurHur
    OwnerAuthor

    merged via #27177

    Verification (Docker):

    php test/repro/new_var_classname.php          # stdClass / Exception:boom
    php bin/vm.php test/repro/new_var_classname.php
    php bin/jit.php test/repro/new_var_classname.php
    ./phpc build -o /tmp/nv test/repro/new_var_classname.php && /tmp/nv
    

    All four print stdClass + Exception:boom.

    Also: JitMcjitEmbedTest::testInjectsBootstrapWhenOnlyClassVariableOrGetClass OK.

    Pillar 1 note: north-star5-verify-fast still fails step 4f-m on master (gen-0 fingerprint — #27162, claimed by PHP Runtime → PHP). Not covered by this PR.

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:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions