diff --git a/phpunit/src/SsaAnalysisTest.php b/phpunit/src/SsaAnalysisTest.php index 89396f87..e0739242 100644 --- a/phpunit/src/SsaAnalysisTest.php +++ b/phpunit/src/SsaAnalysisTest.php @@ -1263,6 +1263,15 @@ class SsaAnalysisTest extends TestCase } } + public function testDetectTypeOfConcatExpressions(): void + { + $concat = new Expr\BinaryOp\Concat(new Scalar\LNumber(1), new Scalar\String_('')); + $concatAssign = new Expr\AssignOp\Concat(new Expr\Variable('value'), new Scalar\LNumber(2)); + + $this->assertSame(Type::STR, $this->invoke('detectTypeOfExpr', $concat)); + $this->assertSame(Type::STR, $this->invoke('detectTypeOfExpr', $concatAssign)); + } + public function testDetectSsaDefTypeNull(): void { $ssaVar = new SsaVar(1, 'x'); diff --git a/src/CompilerBase.php b/src/CompilerBase.php index 2d8f90dd..36da7790 100644 --- a/src/CompilerBase.php +++ b/src/CompilerBase.php @@ -2299,6 +2299,9 @@ class CompilerBase implements PropertyAccessContext case 'Expr_Array': case 'Expr_Cast_Array': return Type::ARRAY; + case 'Expr_BinaryOp_Concat': + case 'Expr_AssignOp_Concat': + return Type::STR; case 'Expr_BinaryOp_Plus': case 'Expr_BinaryOp_Minus': case 'Expr_BinaryOp_Mul':