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 21
21
use PHPStan \Type \MixedType ;
22
22
use PHPStan \Type \StringType ;
23
23
use PHPStan \Type \Type ;
24
+ use PHPStan \Type \TypeCombinator ;
24
25
25
26
trait ObjectTypeTrait
26
27
{
@@ -275,6 +276,10 @@ public function toArrayKey(): Type
275
276
276
277
public function toCoercedArgumentType (bool $ strictTypes ): Type
277
278
{
279
+ if (!$ strictTypes ) {
280
+ return TypeCombinator::union ($ this , $ this ->toString ());
281
+ }
282
+
278
283
return $ this ;
279
284
}
280
285
Original file line number Diff line number Diff line change @@ -571,3 +571,17 @@ public function __toString(): string {
571
571
return 'Foo ' ;
572
572
}
573
573
}
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