Using goto to skip code #4673
-
Given the last issue I submitted turned out to be not an issue because I was doing something silly, I thought I'd try here first. Consider (https://phpstan.org/r/396ec258-69a7-4eb8-b5f2-651be79aca25): <?php declare(strict_types = 1);
/**
* @return string|false
*/
function string_or_false(){
if (rand(1,2)==1)
return "string";
return false;
}
/**
* @param string $s
* @return void
*/
function takes_string(string $s){
echo $s;
}
$a = string_or_false();
if ($a === false)
goto end;
takes_string($a); // line 24
end:
echo "finished"; This reports:
Given that line 24 won't be executed if Context for using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
To save others the bother for this bit: https://phpstan.org/r/392661a4-f07f-4756-870b-4e7976f9ddeb: <?php declare(strict_types = 1);
/**
* @return string|false
*/
function string_or_false(){
if (rand(1,2)==1)
return "string";
return false;
}
/**
* @param string $s
* @return void
*/
function takes_string(string $s){
echo $s;
}
try{
$a = string_or_false();
if ($a === false)
throw new Exception("x");
takes_string($a);
}catch(Exception $e){
echo $e->getMessage();
}finally{
echo "finished";
} No errors. |
Beta Was this translation helpful? Give feedback.
To save others the bother for this bit:
https://phpstan.org/r/392661a4-f07f-4756-870b-4e7976f9ddeb:
No errors.