Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,15 @@ public function findTypeAndMethodNames(): array
$has->yes()
&& !$phpVersion->supportsCallableInstanceMethods()
) {
$methodReflection = $type->getMethod($methodName->getValue(), new OutOfClassScope());
if ($classOrObject->isString()->yes() && !$methodReflection->isStatic()) {
continue;
$isString = $classOrObject->isString();
if ($isString->yes()) {
$methodReflection = $type->getMethod($methodName->getValue(), new OutOfClassScope());

if (!$methodReflection->isStatic()) {
continue;
}
} elseif ($isString->maybe()) {
$has = $has->and(TrinaryLogic::createMaybe());
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,17 @@ public function testPipeOperator(): void
]);
}

public function testMaybeNotCallable(): void
{
$errors = [];
if (PHP_VERSION_ID >= 80000) {
$errors[] = [
"Trying to invoke array{'MaybeNotCallable\\\Bar'|\$this(MaybeNotCallable\Bar), 'doFoo'} but it might not be a callable.",
15,
];
}

$this->analyse([__DIR__ . '/data/maybe-not-callable.php'], $errors);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Functions/data/maybe-not-callable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace MaybeNotCallable;

class Bar
{
private function doFoo()
{
echo 'yes';
}

public function doBar()
{
$cb = [rand(0,1) ? 'MaybeNotCallable\Bar' : $this, 'doFoo'];
$cb();
}
}
Loading