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
Related
#9903 · #3238 · #6011 · #9428 · #10533 pillar 4
Category
language· php-src-strict · trait adaptations (pillar 4)Problem
Trait adaptation
use T { foo as bar; }must alias — the originalfooremains callable andmethod_existsstays true. The VM renames instead:foodisappears and onlybarexists.foo as protected(visibility-only) already matches Zend. Distinct from closed #9903 / #3238 (adaptations missing entirely) and from workinginsteadof.Probed 2026-07-23 on master VM vs host Zend 8.2.32.
use T { foo as bar; }thenmethod_exists($c,'foo')truefalse$c->foo()/$c->bar()1/1C::foo()use T { foo as protected foo2; }then$this->foo()inside classfoophp-src reference
Zend/zend_traits.c— trait alias adaptation (ascopies method under new name; original retained unless visibility-only form)Zend/zend_compile.c—ZEND_AST_TRAIT_ALIASloweringPHP implementation target
lib/(CFG compile + class composition) —as <alias>must register alias and keep original;as <visibility>(no alias name) only changes visibilitygetTraitAliases()already returns the map on current master; runtime method table is the bugruntime/*.cRepro
Done when
.phptundertest/compliance/cases/language/(or traits/)Related
#9903 · #3238 · #6011 · #9428 · #10533 pillar 4