PHPantom version
phpantom_lsp 0.8.0-dirty
Installation method
Pre-built binary from GitHub Releases
Operating system
Windows x86_64
Editor
VS Code
Bug description
PHPantom reports unknown_member inside an elseif branch guarded by is_callable([$value, 'getTime']), using the class type from the previous instanceof branch.
Expected: no diagnostic. The elseif branch only runs when $value is not the class checked in the previous if, and the method call is guarded by is_callable().
Actual: PHPantom reports Method 'getTime' not found on class 'Repro\KnownDateLike'.
Steps to reproduce
- Use any supported PHP version.
- Create a PHP file with:
<?php
namespace Repro;
final class KnownDateLike
{
public function format(): string
{
return 'formatted';
}
}
function formatDateLike(int|string|KnownDateLike|object|null $value): string
{
if ($value === null) {
return '';
}
if (is_object($value)) {
if ($value instanceof KnownDateLike) {
$value = $value->format();
} elseif (is_callable([$value, 'getTime'])) {
$value = (string) $value->getTime();
}
}
return (string) $value;
}
- Run diagnostics.
PHPantom reports:
31 Method 'getTime' not found on class 'Repro\KnownDateLike'
unknown_member
Error output or panic trace
.phpantom.toml
Additional context
Binary source
Originally observed in the VS Code extension v0.5.0. Reproduced with the extension-cached GitHub Releases binary.
PHPantom version
phpantom_lsp 0.8.0-dirty
Installation method
Pre-built binary from GitHub Releases
Operating system
Windows x86_64
Editor
VS Code
Bug description
PHPantom reports
unknown_memberinside anelseifbranch guarded byis_callable([$value, 'getTime']), using the class type from the previousinstanceofbranch.Expected: no diagnostic. The
elseifbranch only runs when$valueis not the class checked in the previousif, and the method call is guarded byis_callable().Actual: PHPantom reports
Method 'getTime' not found on class 'Repro\KnownDateLike'.Steps to reproduce
PHPantom reports:
Error output or panic trace
.phpantom.toml
Additional context
Binary source
Originally observed in the VS Code extension v0.5.0. Reproduced with the extension-cached GitHub Releases binary.