@@ -3580,43 +3580,27 @@ private function processArgs(
3580
3580
$ hasYield = false ;
3581
3581
$ throwPoints = [];
3582
3582
foreach ($ args as $ i => $ arg ) {
3583
- $ originalArg = $ arg ->getAttribute (ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE ) ?? $ arg ;
3584
- $ nodeCallback ($ originalArg , $ scope );
3583
+ $ assignByReference = false ;
3585
3584
if (isset ($ parameters ) && $ parametersAcceptor !== null ) {
3586
- $ byRefType = new MixedType ();
3587
- $ assignByReference = false ;
3588
3585
if (isset ($ parameters [$ i ])) {
3589
3586
$ assignByReference = $ parameters [$ i ]->passedByReference ()->createsNewVariable ();
3590
3587
$ parameterType = $ parameters [$ i ]->getType ();
3591
-
3592
- if (isset ($ paramOutTypes [$ parameters [$ i ]->getName ()])) {
3593
- $ byRefType = $ paramOutTypes [$ parameters [$ i ]->getName ()];
3594
- }
3595
3588
} elseif (count ($ parameters ) > 0 && $ parametersAcceptor ->isVariadic ()) {
3596
3589
$ lastParameter = $ parameters [count ($ parameters ) - 1 ];
3597
3590
$ assignByReference = $ lastParameter ->passedByReference ()->createsNewVariable ();
3598
3591
$ parameterType = $ lastParameter ->getType ();
3599
-
3600
- if (isset ($ paramOutTypes [$ lastParameter ->getName ()])) {
3601
- $ byRefType = $ paramOutTypes [$ lastParameter ->getName ()];
3602
- }
3603
3592
}
3593
+ }
3604
3594
3605
- if ($ assignByReference ) {
3606
- $ argValue = $ arg ->value ;
3607
- if ($ argValue instanceof Variable && is_string ($ argValue ->name )) {
3608
- $ scope = $ scope ->assignVariable ($ argValue ->name , $ byRefType , new MixedType ());
3609
- } else {
3610
- $ scope = $ scope ->invalidateExpression ($ argValue );
3611
- }
3612
- } elseif ($ calleeReflection !== null && $ calleeReflection ->hasSideEffects ()->yes ()) {
3613
- $ argType = $ scope ->getType ($ arg ->value );
3614
- if (!$ argType ->isObject ()->no () || !(new ResourceType ())->isSuperTypeOf ($ argType )->no ()) {
3615
- $ scope = $ scope ->invalidateExpression ($ arg ->value , true );
3616
- }
3595
+ if ($ assignByReference ) {
3596
+ if ($ arg ->value instanceof Variable) {
3597
+ $ scope = $ this ->lookForSetAllowedUndefinedExpressions ($ scope , $ arg ->value );
3617
3598
}
3618
3599
}
3619
3600
3601
+ $ originalArg = $ arg ->getAttribute (ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE ) ?? $ arg ;
3602
+ $ nodeCallback ($ originalArg , $ scope );
3603
+
3620
3604
$ originalScope = $ scope ;
3621
3605
$ scopeToPass = $ scope ;
3622
3606
if ($ i === 0 && $ closureBindScope !== null ) {
@@ -3633,6 +3617,11 @@ private function processArgs(
3633
3617
$ result = $ this ->processExprNode ($ arg ->value , $ scopeToPass , $ nodeCallback , $ context ->enterDeep ());
3634
3618
}
3635
3619
$ scope = $ result ->getScope ();
3620
+ if ($ assignByReference ) {
3621
+ if ($ arg ->value instanceof Variable) {
3622
+ $ scope = $ this ->lookForUnsetAllowedUndefinedExpressions ($ scope , $ arg ->value );
3623
+ }
3624
+ }
3636
3625
$ hasYield = $ hasYield || $ result ->hasYield ();
3637
3626
$ throwPoints = array_merge ($ throwPoints , $ result ->getThrowPoints ());
3638
3627
if ($ i !== 0 || $ closureBindScope === null ) {
@@ -3646,6 +3635,41 @@ private function processArgs(
3646
3635
$ scope = $ scope ->popInFunctionCall ();
3647
3636
}
3648
3637
3638
+ foreach ($ args as $ i => $ arg ) {
3639
+ if (!isset ($ parameters ) || $ parametersAcceptor === null ) {
3640
+ continue ;
3641
+ }
3642
+
3643
+ $ byRefType = new MixedType ();
3644
+ $ assignByReference = false ;
3645
+ if (isset ($ parameters [$ i ])) {
3646
+ $ assignByReference = $ parameters [$ i ]->passedByReference ()->createsNewVariable ();
3647
+ if (isset ($ paramOutTypes [$ parameters [$ i ]->getName ()])) {
3648
+ $ byRefType = $ paramOutTypes [$ parameters [$ i ]->getName ()];
3649
+ }
3650
+ } elseif (count ($ parameters ) > 0 && $ parametersAcceptor ->isVariadic ()) {
3651
+ $ lastParameter = $ parameters [count ($ parameters ) - 1 ];
3652
+ $ assignByReference = $ lastParameter ->passedByReference ()->createsNewVariable ();
3653
+ if (isset ($ paramOutTypes [$ lastParameter ->getName ()])) {
3654
+ $ byRefType = $ paramOutTypes [$ lastParameter ->getName ()];
3655
+ }
3656
+ }
3657
+
3658
+ if ($ assignByReference ) {
3659
+ $ argValue = $ arg ->value ;
3660
+ if ($ argValue instanceof Variable && is_string ($ argValue ->name )) {
3661
+ $ scope = $ scope ->assignVariable ($ argValue ->name , $ byRefType , new MixedType ());
3662
+ } else {
3663
+ $ scope = $ scope ->invalidateExpression ($ argValue );
3664
+ }
3665
+ } elseif ($ calleeReflection !== null && $ calleeReflection ->hasSideEffects ()->yes ()) {
3666
+ $ argType = $ scope ->getType ($ arg ->value );
3667
+ if (!$ argType ->isObject ()->no () || !(new ResourceType ())->isSuperTypeOf ($ argType )->no ()) {
3668
+ $ scope = $ scope ->invalidateExpression ($ arg ->value , true );
3669
+ }
3670
+ }
3671
+ }
3672
+
3649
3673
return new ExpressionResult ($ scope , $ hasYield , $ throwPoints );
3650
3674
}
3651
3675
0 commit comments