You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Conditional return type on a private method always takes the false branch #97
On a private method, a conditional return type always takes the false branch. The same method as protected or public works.
<?php
namespace App;
interface WithCount {}
final class Counted implements WithCount {}
final class Finder
{
/** @return ($command is WithCount ? list<object> : list<int>) */
private function result(object $command): array
{
return [new \stdClass()];
}
public function run(): array
{
return $this->result(new Counted());
}
}
(new Finder())->run();
echo "OK\n";
Fatal error: Uncaught TypePHP\Exception\TypeError: App\Finder::result(): Return value[0] must be of type int, stdClass returned in playground.php on line 13
The same method declared protected or public prints OK. A value condition on a private method fails the same way: @return ($limit is 1 ? object : list<object>) called with 1 gives Return value must be a list, stdClass returned.
Tested on v0.10.26 and on main (2ec0426).
$this->pick(true) gives Return value must be of type int, string 's' returned. The same method as protected passes.
In our codebase it hits a private getInternalMetadataByKey(string $key, bool $outputValue = false) with @return ($outputValue is true ? mixed[]|string|null : IMetadata), which every entity's metadata accessors go through, so the run stops at the first metadata read in four modules.
Activity
rcalicdan commentedon Oct 3, 2026
Good fine, this is cause by a checking lapses inside Typephp RuntimeCheckers engine, will be fixing this on next release..
fdaviddpt commentedon Oct 3, 2026
A data point before the release: this still reproduces on
next-minor-released(PR #100) at f617372, PHP 8.2, cache cleared.$this->pick(true)givesReturn value must be of type int, string 's' returned. The same method asprotectedpasses.In our codebase it hits a private
getInternalMetadataByKey(string $key, bool $outputValue = false)with@return ($outputValue is true ? mixed[]|string|null : IMetadata), which every entity's metadata accessors go through, so the run stops at the first metadata read in four modules.