Skip to content

Preserve get_called_class in directly compiled methods - #107

Open
yavon007 wants to merge 1 commit into
swoole:masterfrom
yavon007:codex/direct-get-called-class
Open

Preserve get_called_class in directly compiled methods#107
yavon007 wants to merge 1 commit into
swoole:masterfrom
yavon007:codex/direct-get-called-class

Conversation

@yavon007

Copy link
Copy Markdown
Contributor

A final instance method on a concrete class can be called directly by generated
C++ code. If it calls get_called_class(), the generated runtime function call
has no Zend method frame to inspect and raises “must be called from within a
class”, even though the same PHP program correctly returns the runtime class.

For zero-argument named calls resolved to this built-in in ordinary compiled
methods, reuse the receiver/called-scope machinery used by static::class.
Apply this after user-function resolution and argument validation. Use the
parser-resolved function target to distinguish case-insensitive aliases. Leave
dynamic calls, first-class callables, Native-class restrictions, and calls
outside methods on their existing paths. Do not expand devirtualization.

Validation: 149 focused PHPUnit tests / 302 assertions pass. A new compiled
PHPT matches PHP and EXPECT for inherited instance/static calls, traits,
mixed-case fully qualified names, aliases, closures, runtime subclasses,
namespaced function shadowing, and the error outside class scope. The minimal
unmodified-compiler repro exits 255; the fixed build matches PHP with empty
stderr. Tested on Linux ARM64, GCC O2, PHP 8.5.10 ZTS and PHPX 4b3a472.

This is a correctness fix with no claimed benchmark gain; it is not a general
solution for every runtime API that inspects Zend execution frames.

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.

1 participant