Preserve get_called_class in directly compiled methods - #107
Open
yavon007 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 callhas 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.