Ref T13250. Two issues here:
- When you (string)$x, if __toString() raises an exception: you get a fatal error, not an exception.
- When you (string)$x, if $x is an array, you get the string "Array". This is almost certainly never desirable.
We can't fix this in the general case (and sometime string casts will still happen implicitly and there's nothing we can do about it), but we can implement a better version of (string) at the application layer for cases where we're doing an explicit cast.
(I believe there's a legitimate-ish reason that __toString() can't always raise exceptions, like if you call strlen($obj) and it needs to be implicitly cast inside parameter construction for the call or something? So this behavior isn't completely pointless, probably, just not-so-great.)