Skip to content

Language: trait method as alias drops original name — Zend keeps both (re-#9903, Zend/zend_traits.c) #22718

Description

@PurHur

Category

language · php-src-strict · trait adaptations (pillar 4)

Problem

Trait adaptation use T { foo as bar; } must alias — the original foo remains callable and method_exists stays true. The VM renames instead: foo disappears and only bar exists.

foo as protected (visibility-only) already matches Zend. Distinct from closed #9903 / #3238 (adaptations missing entirely) and from working insteadof.

Probed 2026-07-23 on master VM vs host Zend 8.2.32.

Repro Zend 8.2+ VM (2026-07-23)
use T { foo as bar; } then method_exists($c,'foo') true false
$c->foo() / $c->bar() 1 / 1 Fatal undefined C::foo()
use T { foo as protected foo2; } then $this->foo() inside class works Fatal undefined foo

php-src reference

PHP implementation target

  • Trait adaptation / method table merge in lib/ (CFG compile + class composition) — as <alias> must register alias and keep original; as <visibility> (no alias name) only changes visibility
  • Reflection getTraitAliases() already returns the map on current master; runtime method table is the bug
  • No new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/trait_alias.php <<'\''PHP'\''
<?php
trait T { public function foo(){ return 1; } }
class C { use T { foo as bar; } }
$c = new C;
var_export(method_exists($c, "foo")); echo "\n";
var_export(method_exists($c, "bar")); echo "\n";
echo $c->foo(), " ", $c->bar(), "\n";
PHP
php /tmp/trait_alias.php; php bin/vm.php /tmp/trait_alias.php'

Done when

  • Table rows match Zend on VM (JIT/AOT if in scope)
  • Compliance .phpt under test/compliance/cases/language/ (or traits/)
  • php-src-strict; no php-compiler-strict shortcut

Related

#9903 · #3238 · #6011 · #9428 · #10533 pillar 4

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