PossiblyInvalidCast# Error at levels 1–3 Default (2) Error Emitted when attempting to cast a value that may not be castable <?php class A {} class B { public function __toString() { return 'hello'; } } $c = (string) (rand(0, 1) ? new A() : new B()); Get Psalm news by email News about Psalm, a few emails a month. You can unsubscribe at any time. Email Subscribe I accept the privacy policy