Skip to content

Language: trait insteadof parent class compile error wrong — Zend "not a trait" (Zend/zend_compile.c) #32129

Description

@PurHur

Category

language · php-src-strict · traits · compile-time error text

Problem

Using a parent class name in a trait insteadof clause is a compile-time error in php-src. This compiler emits a generic Could not find trait P message instead of Zend's explicit "Class P is not a trait, Only traits may be used in 'as' and 'insteadof' statements".

Repro Zend 8.2+ VM/JIT compile (2026-08-18 @ 2f0c85a98d)
class P{}; trait T{}; class C extends P { use T { T::m insteadof P; } } Fatal: Class P is not a trait… Could not find trait P

Workers/compliance diff on error text, not just failure presence.

php-src reference

PHP implementation target

  • lib/ trait compilation / conflict resolution — when insteadof/as operand resolves to a class that is not a trait, emit Zend message verbatim
  • Keep logic in PHP compile pipeline; no new C runtime branches

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_trait_insteadof_parent.php 2>&1 | head -1'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_trait_insteadof_parent.php 2>&1 | head -1'

Done when

  • Compile abort message matches Zend substring is not a trait with class name P on VM and JIT
  • Compliance .phpt guard under test/compliance/cases/language/trait_insteadof_parent*.phpt asserting %is not a trait%
  • 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: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