File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ PHP NEWS
2525 operators" RFC, meaning that incrementing non-numeric strings is now
2626 deprecated. (Girgias).
2727 . Various closure binding issues are now deprecated. (alexandre-daubois)
28+ . Fixed bug GH-18373 (Don't substitute self/parent with anonymous class).
29+ (ilutov)
2830
2931- Filter:
3032 . Added support for configuring the URI parser for FILTER_VALIDATE_URL
Original file line number Diff line number Diff line change 1515
1616?>
1717--EXPECT--
18- Cannot assign int to property class@anonymous::$v of type class@anonymous
18+ Cannot assign int to property class@anonymous::$v of type self
Original file line number Diff line number Diff line change @@ -7091,16 +7091,20 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
70917091 ZEND_ASSERT (fetch_type == ZEND_FETCH_CLASS_SELF || fetch_type == ZEND_FETCH_CLASS_PARENT );
70927092
70937093 zend_ensure_valid_class_fetch_type (fetch_type );
7094+
7095+ bool substitute_self_parent = zend_is_scope_known ()
7096+ && !(CG (active_class_entry )-> ce_flags & ZEND_ACC_ANON_CLASS );
7097+
70947098 if (fetch_type == ZEND_FETCH_CLASS_SELF ) {
70957099 /* Scope might be unknown for unbound closures and traits */
7096- if (zend_is_scope_known () ) {
7100+ if (substitute_self_parent ) {
70977101 class_name = CG (active_class_entry )-> name ;
70987102 ZEND_ASSERT (class_name && "must know class name when resolving self type at compile time" );
70997103 }
71007104 } else {
71017105 ZEND_ASSERT (fetch_type == ZEND_FETCH_CLASS_PARENT );
71027106 /* Scope might be unknown for unbound closures and traits */
7103- if (zend_is_scope_known () ) {
7107+ if (substitute_self_parent ) {
71047108 class_name = CG (active_class_entry )-> parent_name ;
71057109 ZEND_ASSERT (class_name && "must know class name when resolving parent type at compile time" );
71067110 }
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-18373: Don't substitute self/parent with anonymous class
3+ --FILE--
4+ <?php
5+
6+ $ o = new class () {
7+ public function test (): self {}
8+ };
9+
10+ echo (new ReflectionClass ($ o ))->getMethod ('test ' )->getReturnType ()->getName (), "\n" ;
11+
12+ ?>
13+ --EXPECT--
14+ self
You can’t perform that action at this time.
0 commit comments