mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Don't substitute self/parent with anonymous class
Fixes GH-18373 Closes GH-19537
This commit is contained in:
2
NEWS
2
NEWS
@@ -25,6 +25,8 @@ PHP NEWS
|
||||
operators" RFC, meaning that incrementing non-numeric strings is now
|
||||
deprecated. (Girgias).
|
||||
. Various closure binding issues are now deprecated. (alexandre-daubois)
|
||||
. Fixed bug GH-18373 (Don't substitute self/parent with anonymous class).
|
||||
(ilutov)
|
||||
|
||||
- Filter:
|
||||
. Added support for configuring the URI parser for FILTER_VALIDATE_URL
|
||||
|
||||
@@ -15,4 +15,4 @@ try {
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot assign int to property class@anonymous::$v of type class@anonymous
|
||||
Cannot assign int to property class@anonymous::$v of type self
|
||||
|
||||
@@ -7091,16 +7091,20 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
|
||||
ZEND_ASSERT(fetch_type == ZEND_FETCH_CLASS_SELF || fetch_type == ZEND_FETCH_CLASS_PARENT);
|
||||
|
||||
zend_ensure_valid_class_fetch_type(fetch_type);
|
||||
|
||||
bool substitute_self_parent = zend_is_scope_known()
|
||||
&& !(CG(active_class_entry)->ce_flags & ZEND_ACC_ANON_CLASS);
|
||||
|
||||
if (fetch_type == ZEND_FETCH_CLASS_SELF) {
|
||||
/* Scope might be unknown for unbound closures and traits */
|
||||
if (zend_is_scope_known()) {
|
||||
if (substitute_self_parent) {
|
||||
class_name = CG(active_class_entry)->name;
|
||||
ZEND_ASSERT(class_name && "must know class name when resolving self type at compile time");
|
||||
}
|
||||
} else {
|
||||
ZEND_ASSERT(fetch_type == ZEND_FETCH_CLASS_PARENT);
|
||||
/* Scope might be unknown for unbound closures and traits */
|
||||
if (zend_is_scope_known()) {
|
||||
if (substitute_self_parent) {
|
||||
class_name = CG(active_class_entry)->parent_name;
|
||||
ZEND_ASSERT(class_name && "must know class name when resolving parent type at compile time");
|
||||
}
|
||||
|
||||
14
ext/reflection/tests/gh18373.phpt
Normal file
14
ext/reflection/tests/gh18373.phpt
Normal file
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
GH-18373: Don't substitute self/parent with anonymous class
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$o = new class() {
|
||||
public function test(): self {}
|
||||
};
|
||||
|
||||
echo (new ReflectionClass($o))->getMethod('test')->getReturnType()->getName(), "\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
self
|
||||
Reference in New Issue
Block a user