Skip to content

Language: keep original trait method under as alias (#22718) - #22727

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-22718-trait-as-alias
Jul 23, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-22718-trait-as-alias

Conversation

@PurHur

@PurHur PurHur commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Zend use T { foo as bar; } aliases — original foo stays callable (method_exists true). The VM/JIT previously renamed (unset the original).
  • Fixed in lib/VM.php, lib/JIT.php, and lib/Compiler/TraitComposedMethodResolver.php (php-src-strict; Zend/zend_traits.c).
  • Visibility-only as protected unchanged; foo as protected foo2 keeps both.

Closes #22718

Test plan

  • Issue repro (Zend + VM):
php /tmp/trait_alias.php; php bin/vm.php /tmp/trait_alias.php
# true / true / 1 1
  • php -d memory_limit=512M vendor/bin/phpunit --filter TraitAdaptationTest → OK (9)
  • php -d memory_limit=512M vendor/bin/phpunit --filter trait_as_alias → OK (6)
  • Related Override/trait filters → OK (56, 12 skipped)

Verification transcript

=== Zend ===
true
true
1 1
=== VM (after fix) ===
true
true
1 1
=== Zend/VM visibility+alias ===
2
true
true

php-src ref: Zend/zend_traits.c trait alias adaptation.

Made with Cursor

Zend aliases with `use T { foo as bar; }` — the original name stays
callable. Stop unsetting the merged method in VM/JIT/compose resolver.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit d92f719 into master Jul 23, 2026
@PurHur
PurHur deleted the agent/issue-22718-trait-as-alias branch July 23, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant