Skip to content

Commit 4bb13d8

Browse files
committed
support Stringable objects
1 parent 76e1258 commit 4bb13d8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Type/ObjectType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,10 @@ public function toArrayKey(): Type
706706

707707
public function toCoercedArgumentType(bool $strictTypes): Type
708708
{
709+
if (!$strictTypes) {
710+
return TypeCombinator::union($this, $this->toString());
711+
}
712+
709713
return $this;
710714
}
711715

tests/PHPStan/Analyser/nsrt/bug-12393b.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,15 @@ public function doFoo(array $list): void
534534
}
535535

536536
}
537+
538+
class StringableFoo {
539+
private string $foo;
540+
541+
public function doFoo(StringableFoo $foo): void {
542+
$this->foo = $foo;
543+
assertType('string', $this->foo);
544+
}
545+
public function __toString(): string {
546+
return 'Foo';
547+
}
548+
}

0 commit comments

Comments
 (0)