Skip to content

Language: parent::__construct() with no parent ctor — wrong Error (Zend Cannot call constructor) #25909

Description

@PurHur

Category

language · php-src-strict · constructors

Problem

Calling parent::__construct() when the parent class declares no constructor must throw Error: Cannot call constructor (Zend). VM/JIT throw a different Error shaped like a missing static method, with a lowercased class name.

Probed 2026-07-31 Zend 8.2.32 vs bin/vm.php / bin/jit.php @ fad4609ee.

Repro Zend 8.2 VM/JIT
parent::__construct() in child of empty parent Error:Cannot call constructor Error:Call to undefined static method parentnoctor::__construct()
class ParentNoCtor {}
class Child extends ParentNoCtor {
    public function __construct() { parent::__construct(); }
}
new Child; // Zend: Cannot call constructor

php-src reference

PHP implementation target

  • Parent ctor dispatch in lib/VM + JIT call lowering: when parent has no __construct, throw Zend’s Cannot call constructor (not undefined-static-method)
  • PHP-in-PHP; no new C

Repro

./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_parent_construct_no_parent_ctor.php; php bin/vm.php test/repro/maintainer_gap_parent_construct_no_parent_ctor.php; php bin/jit.php test/repro/maintainer_gap_parent_construct_no_parent_ctor.php'

Done when

  • Message is exactly Cannot call constructor (Error) on VM + JIT
  • try/catch still catches it (already does)
  • Compliance / repro guard; php-src-strict

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething 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