@@ -3731,41 +3731,21 @@ private function enterAnonymousFunctionWithoutReflection(
3731
3731
foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
3732
3732
$ expr = $ typeHolder ->getExpr ();
3733
3733
3734
- if (
3735
- $ expr instanceof PropertyFetch
3736
- && $ expr ->name instanceof Node \Identifier
3737
- && $ expr ->var instanceof Variable
3738
- && is_string ($ expr ->var ->name )
3739
- && $ expr ->var ->name === 'this '
3740
- && !$ closure ->static
3741
- && $ this ->hasVariableType ('this ' )->yes ()
3742
- && $ this ->phpVersion ->supportsReadOnlyProperties ()
3743
- ) {
3744
- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3745
- if ($ propertyReflection === null ) {
3746
- continue ;
3747
- }
3748
- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3749
- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3750
- continue ;
3751
- }
3752
- } else {
3753
- if ($ expr instanceof Variable) {
3754
- continue ;
3755
- }
3734
+ if ($ expr instanceof Variable) {
3735
+ continue ;
3736
+ }
3756
3737
3757
- $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3758
- if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3759
- continue ;
3760
- }
3738
+ $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3739
+ if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3740
+ continue ;
3741
+ }
3761
3742
3762
- foreach ($ variables as $ variable ) {
3763
- if (!is_string ($ variable ->name )) {
3764
- continue 2 ;
3765
- }
3766
- if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3767
- continue 2 ;
3768
- }
3743
+ foreach ($ variables as $ variable ) {
3744
+ if (!is_string ($ variable ->name )) {
3745
+ continue 2 ;
3746
+ }
3747
+ if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3748
+ continue 2 ;
3769
3749
}
3770
3750
}
3771
3751
@@ -3776,6 +3756,34 @@ private function enterAnonymousFunctionWithoutReflection(
3776
3756
$ node = new Variable ('this ' );
3777
3757
$ expressionTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getType ($ node ));
3778
3758
$ nativeTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getNativeType ($ node ));
3759
+
3760
+ if ($ this ->phpVersion ->supportsReadOnlyProperties ()) {
3761
+ foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
3762
+ $ expr = $ typeHolder ->getExpr ();
3763
+
3764
+ if (
3765
+ !$ expr instanceof PropertyFetch
3766
+ || !$ expr ->name instanceof Node \Identifier
3767
+ || !$ expr ->var instanceof Variable
3768
+ || !is_string ($ expr ->var ->name )
3769
+ || $ expr ->var ->name !== 'this '
3770
+ ) {
3771
+ continue ;
3772
+ }
3773
+
3774
+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3775
+ if ($ propertyReflection === null ) {
3776
+ continue ;
3777
+ }
3778
+
3779
+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3780
+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3781
+ continue ;
3782
+ }
3783
+
3784
+ $ expressionTypes [$ exprString ] = $ typeHolder ;
3785
+ }
3786
+ }
3779
3787
}
3780
3788
3781
3789
return $ this ->scopeFactory ->create (
0 commit comments