@@ -2653,7 +2653,7 @@ public function enterAnonymousFunction(
26532653 $ scope ->getNamespace (),
26542654 $ scope ->expressionTypes ,
26552655 $ scope ->nativeExpressionTypes ,
2656- [] ,
2656+ $ scope -> conditionalExpressions ,
26572657 $ scope ->inClosureBindScopeClasses ,
26582658 $ anonymousFunctionReflection ,
26592659 true ,
@@ -2703,12 +2703,14 @@ private function enterAnonymousFunctionWithoutReflection(
27032703 }
27042704
27052705 $ nonRefVariableNames = [];
2706+ $ useVariableNames = [];
27062707 foreach ($ closure ->uses as $ use ) {
27072708 if (!is_string ($ use ->var ->name )) {
27082709 throw new ShouldNotHappenException ();
27092710 }
27102711 $ variableName = $ use ->var ->name ;
27112712 $ paramExprString = '$ ' . $ use ->var ->name ;
2713+ $ useVariableNames [$ paramExprString ] = true ;
27122714 if ($ use ->byRef ) {
27132715 $ holder = ExpressionTypeHolder::createYes ($ use ->var , new MixedType ());
27142716 $ expressionTypes [$ paramExprString ] = $ holder ;
@@ -2774,14 +2776,33 @@ private function enterAnonymousFunctionWithoutReflection(
27742776 }
27752777 }
27762778
2779+ $ filteredConditionalExpressions = [];
2780+ foreach ($ this ->conditionalExpressions as $ conditionalExprString => $ holders ) {
2781+ if (!array_key_exists ($ conditionalExprString , $ useVariableNames )) {
2782+ continue ;
2783+ }
2784+ $ filteredHolders = [];
2785+ foreach ($ holders as $ holder ) {
2786+ foreach ($ holder ->getConditionExpressionTypeHolders () as $ holderExprString => $ conditionalTypeHolder ) {
2787+ if (!array_key_exists ($ holderExprString , $ useVariableNames )) {
2788+ continue 2 ;
2789+ }
2790+ }
2791+ $ filteredHolders [] = $ holder ;
2792+ }
2793+ if ($ filteredHolders !== []) {
2794+ $ filteredConditionalExpressions [$ conditionalExprString ] = $ filteredHolders ;
2795+ }
2796+ }
2797+
27772798 return $ this ->scopeFactory ->create (
27782799 $ this ->context ,
27792800 $ this ->isDeclareStrictTypes (),
27802801 $ this ->getFunction (),
27812802 $ this ->getNamespace (),
27822803 array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
27832804 array_merge ($ this ->getNativeConstantTypes (), $ nativeTypes ),
2784- [] ,
2805+ $ filteredConditionalExpressions ,
27852806 $ this ->inClosureBindScopeClasses ,
27862807 new ClosureType (),
27872808 true ,
0 commit comments