@@ -3708,41 +3708,21 @@ private function enterAnonymousFunctionWithoutReflection(
3708
3708
foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
3709
3709
$ expr = $ typeHolder ->getExpr ();
3710
3710
3711
- if (
3712
- $ expr instanceof PropertyFetch
3713
- && $ expr ->name instanceof Node \Identifier
3714
- && $ expr ->var instanceof Variable
3715
- && is_string ($ expr ->var ->name )
3716
- && $ expr ->var ->name === 'this '
3717
- && !$ closure ->static
3718
- && $ this ->hasVariableType ('this ' )->yes ()
3719
- && $ this ->phpVersion ->supportsReadOnlyProperties ()
3720
- ) {
3721
- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3722
- if ($ propertyReflection === null ) {
3723
- continue ;
3724
- }
3725
- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3726
- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3727
- continue ;
3728
- }
3729
- } else {
3730
- if ($ expr instanceof Variable) {
3731
- continue ;
3732
- }
3711
+ if ($ expr instanceof Variable) {
3712
+ continue ;
3713
+ }
3733
3714
3734
- $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3735
- if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3736
- continue ;
3737
- }
3715
+ $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3716
+ if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3717
+ continue ;
3718
+ }
3738
3719
3739
- foreach ($ variables as $ variable ) {
3740
- if (!is_string ($ variable ->name )) {
3741
- continue 2 ;
3742
- }
3743
- if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3744
- continue 2 ;
3745
- }
3720
+ foreach ($ variables as $ variable ) {
3721
+ if (!is_string ($ variable ->name )) {
3722
+ continue 2 ;
3723
+ }
3724
+ if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3725
+ continue 2 ;
3746
3726
}
3747
3727
}
3748
3728
@@ -3753,6 +3733,34 @@ private function enterAnonymousFunctionWithoutReflection(
3753
3733
$ node = new Variable ('this ' );
3754
3734
$ expressionTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getType ($ node ));
3755
3735
$ nativeTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getNativeType ($ node ));
3736
+
3737
+ if ($ this ->phpVersion ->supportsReadOnlyProperties ()) {
3738
+ foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
3739
+ $ expr = $ typeHolder ->getExpr ();
3740
+
3741
+ if (
3742
+ !$ expr instanceof PropertyFetch
3743
+ || !$ expr ->name instanceof Node \Identifier
3744
+ || !$ expr ->var instanceof Variable
3745
+ || !is_string ($ expr ->var ->name )
3746
+ || $ expr ->var ->name !== 'this '
3747
+ ) {
3748
+ continue ;
3749
+ }
3750
+
3751
+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3752
+ if ($ propertyReflection === null ) {
3753
+ continue ;
3754
+ }
3755
+
3756
+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3757
+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3758
+ continue ;
3759
+ }
3760
+
3761
+ $ expressionTypes [$ exprString ] = $ typeHolder ;
3762
+ }
3763
+ }
3756
3764
}
3757
3765
3758
3766
return $ this ->scopeFactory ->create (
0 commit comments