File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 2121use PHPStan \Type \MixedType ;
2222use PHPStan \Type \StringType ;
2323use PHPStan \Type \Type ;
24+ use PHPStan \Type \TypeCombinator ;
2425
2526trait ObjectTypeTrait
2627{
@@ -275,6 +276,10 @@ public function toArrayKey(): Type
275276
276277 public function toCoercedArgumentType (bool $ strictTypes ): Type
277278 {
279+ if (!$ strictTypes ) {
280+ return TypeCombinator::union ($ this , $ this ->toString ());
281+ }
282+
278283 return $ this ;
279284 }
280285
Original file line number Diff line number Diff line change @@ -571,3 +571,17 @@ public function __toString(): string {
571571 return 'Foo ' ;
572572 }
573573}
574+
575+ class ObjectWithToStringMethod {
576+ private string $ foo ;
577+
578+ public function doFoo (object $ foo ): void {
579+ if (method_exists ($ foo , '__toString ' )) {
580+ $ this ->foo = $ foo ;
581+ assertType ('string ' , $ this ->foo );
582+ }
583+ }
584+ public function __toString (): string {
585+ return 'Foo ' ;
586+ }
587+ }
You can’t perform that action at this time.
0 commit comments