The following code has a return value (unless an exception is thrown) but generates the warning 'sample': not all code paths return a value PHP(PHP0405):
public function sample(): bool
{
try {
// create connection
if ($_SESSION['error'])
{
throw new \Exception(123);
}
return true;
} finally {
// close connection
}
}
Whereas the same function without try/finally appears to be OK:
public function sample(): bool
{
if ($_SESSION['error'])
{
throw new \Exception(123);
}
return true;
}
And the same function without the exception also appears to be OK:
public function sample(): bool
{
try {
// create connection
return true;
}
finally {
// close connection
}
}
Note: possibly related to this past issue: https://community.devsense.com/d/629-issue-on-detect-code-return
Environment: VSCode 1.89.1 with PHP Tools v1.48.15635