Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error on constant('') #3013

Open
wants to merge 10 commits into
base: 1.11.x
Choose a base branch
from
3 changes: 3 additions & 0 deletions src/Type/Php/ConstantFunctionReturnTypeExtension.php
Expand Up @@ -36,6 +36,9 @@ public function getTypeFromFunctionCall(

$results = [];
foreach ($nameType->getConstantStrings() as $constantName) {
if ($constantName->getValue() === '') {
return null;
}
$results[] = $scope->getType($this->constantHelper->createExprFromConstantName($constantName->getValue()));
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Expand Up @@ -1330,6 +1330,12 @@ public function testBug10772(): void
$this->assertNoErrors($errors);
}

public function testBug10867(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-10867.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Analyser/data/bug-10867.php
@@ -0,0 +1,10 @@
<?php
namespace Bug10867;

function doFoo():void {
$sysERR = '';
?>

<p><?php echo constant($sysERR); ?></p>
<?php
}