Skip to content

Language: eval() allows overriding final methods — Zend E_COMPILE_ERROR (Zend/zend_inheritance.c) #24884

Closed

Description

@PurHur

Category

language · php-src-strict · inheritance / eval

Problem

Direct compile of a child that overrides a final method correctly fatals. The same declaration via eval() succeeds under the VM and prints ok. Zend fatals for both paths (Cannot override final method A::f()).

Path Zend 8.2 (2026-07-29) VM
class B extends A { function f() {} } (source) Fatal: Cannot override final method parseAndCompile failure (OK)
eval('class B extends A { function f() {} }') Fatal: Cannot override final method (exit 255) ok (exit 0)

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/finaleval.php <<'"'"'PHP'"'"'
<?php
class A { final function f() {} }
try {
    eval("class B extends A { function f() {} }");
    echo "ok\n";
} catch (Throwable $e) {
    echo get_class($e), ":", $e->getMessage(), "\n";
}
PHP
echo ZEND:; php /tmp/finaleval.php 2>&1; echo RC:$?
echo VM:; php bin/vm.php /tmp/finaleval.php 2>&1; echo RC:$?'

Done when

  • eval of a child overriding a final method fatals like Zend (same message class)
  • Direct source compile remains fatal
  • Repro/compliance guard; php-src-strict

Activity

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

    @PurHur
    OwnerAuthor

    claim: worker-lane-C — starting this run

    Trust snapshot (pre-triage):

    • docker info: ok
    • bootstrap-inventory --check: red (file-list/construct-flag drift vs committed doc; known master skew — not regenerating unless this fix touches vm.php path)
    • Will run issue repro + targeted guard after fix; release-readiness if needed for merge.
  3. PurHur commented on Jul 29, 2026

    @PurHur
    OwnerAuthor

    Merged via #24900

    Verification

    • php bin/vm.php issue repro: PHP Fatal error: Cannot override final method A::f() exit 255 (try/catch does not catch — Zend parity)
    • Direct source compile still fatal via FinalMethodOverrideCheck
    • Trait + grandparent eval paths also fatal
    • phpunit --filter 'final_method_eval_override_fatal|FinalMethodOverrideCheckTest' → OK (7 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: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