[$object, 'method'] array callable directly returns that
method's return type. The array literal names its target exactly, so a tool
can resolve the call the same way it resolves $object->method().
References:
- https://www.php.net/manual/en/language.types.callable.php| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 | Pass | callables_array_callable_invocation.php:39: Call to undeclared method \Conformance\Tests\CallablesArrayCallableInvocation\User::missing [PhanUndeclaredMethod] |
| phpstan | 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 | Pass reported Lv.2+ | callables_array_callable_invocation.php:39: Call to an undefined method Conformance\Tests\CallablesArrayCallableInvocation\User::missing(). [reported-from-level=2] callables_array_callable_invocation.php:39: Parameter #1 (mixed) of echo cannot be converted to string. [reported-from-level=10] With strict-rulescallables_array_callable_invocation.php:39: Call to an undefined method Conformance\Tests\CallablesArrayCallableInvocation\User::missing(). callables_array_callable_invocation.php:39: Parameter #1 (mixed) of echo cannot be converted to string. |
| psalm | 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c next: 7.0.0-rc2 |
Fail | callables_array_callable_invocation.php:37: Argument 1 of echo cannot be mixed, expecting string [MixedArgument] callables_array_callable_invocation.php:37: Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall] callables_array_callable_invocation.php:39: Argument 1 of echo cannot be mixed, expecting string [MixedArgument] callables_array_callable_invocation.php:39: Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall] Expectation diffLine 37: Expected valid value to be accepted, got ["Argument 1 of echo cannot be mixed, expecting string [MixedArgument]","Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall]"] |
| mago | 1.57.0mago 1.57.0 | Pass | callables_array_callable_invocation.php:39: Method `missing` does not exist on type `Conformance\Tests\CallablesArrayCallableInvocation\User`. [non-existent-method] callables_array_callable_invocation.php:39: The first value for `echo` is too general. [mixed-argument] |
| mir | 0.87.0mir 0.87.0 | Fail | callables_array_callable_invocation.php:37: MixedMethodCall: Method name() called on mixed type [MIR1202] callables_array_callable_invocation.php:39: MixedMethodCall: Method missing() called on mixed type [MIR1202] Expectation diffLine 37: Expected valid value to be accepted, got ["MixedMethodCall: Method name() called on mixed type [MIR1202]"] |
| phpantom | 0.11.1phpantom_lsp 0.11.1 | Fail | callables_array_callable_invocation.php:37: Cannot verify method 'name' — type of '$find()' could not be resolved [unresolved_member_access] callables_array_callable_invocation.php:39: Cannot verify method 'missing' — type of '$lookup()' could not be resolved [unresolved_member_access] Expectation diffLine 37: Expected valid value to be accepted, got ["Cannot verify method 'name' — type of '$find()' could not be resolved [unresolved_member_access]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Fail | callables_array_callable_invocation.php:37: Expected type 'string|Stringable|null'. Found 'mixed'. [P1006] callables_array_callable_invocation.php:37: Expected type 'object'. Found 'mixed'. [P1006] callables_array_callable_invocation.php:39: Expected type 'string|Stringable|null'. Found 'mixed'. [P1006] callables_array_callable_invocation.php:39: Expected type 'object'. Found 'mixed'. [P1006] Expectation diffLine 37: Expected valid value to be accepted, got ["Expected type 'string|Stringable|null'. Found 'mixed'. [P1006]","Expected type 'object'. Found 'mixed'. [P1006]"] |
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Fail | No diagnostics reported. Expectation diffLine 39: Expected 1 error(s) |
| phpy | 1.0.19409phpy 1.0.19409 | Fail | No diagnostics reported. Expectation diffLine 39: Expected 1 error(s) |
| qodana | 262.10968.76PhpStorm 262.10968.76 | Fail | No diagnostics reported. Expectation diffLine 39: Expected 1 error(s) |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Fail | No diagnostics reported. Expectation diffLine 39: Expected 1 error(s) |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Fail | No diagnostics reported. Expectation diffLine 39: Expected 1 error(s) |
| phpstan-strict | 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 | Pass | callables_array_callable_invocation.php:39: Call to an undefined method Conformance\Tests\CallablesArrayCallableInvocation\User::missing(). callables_array_callable_invocation.php:39: Parameter #1 (mixed) of echo cannot be converted to string. |
| psalm-next | 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 | Fail | callables_array_callable_invocation.php:37: Argument 1 of echo cannot be mixed, expecting string [MixedArgument] callables_array_callable_invocation.php:37: Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall] callables_array_callable_invocation.php:39: Argument 1 of echo cannot be mixed, expecting string [MixedArgument] callables_array_callable_invocation.php:39: Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall] Expectation diffLine 37: Expected valid value to be accepted, got ["Argument 1 of echo cannot be mixed, expecting string [MixedArgument]","Cannot determine the type of the object on the left hand side of this expression [MixedMethodCall]"] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\CallablesArrayCallableInvocation;
/**
* Return type of an invoked array callable.
*
* Invoking a `[$object, 'method']` array callable directly returns that
* method's return type. The array literal names its target exactly, so a tool
* can resolve the call the same way it resolves `$object->method()`.
*
* References:
* - https://www.php.net/manual/en/language.types.callable.php
*/
final class User
{
public function name(): string
{
return 'user';
}
}
final class Repository
{
public function find(): User
{
return new User();
}
}
function invokesArrayCallable(Repository $repository): void
{
$find = [$repository, 'find'];
echo $find()->name(); // V
$lookup = [$repository, 'find'];
echo $lookup()->missing(); // E: the call returns a User
}