I like Rust's From and TryFrom traits, which allow types to define conversions into or from other types. The From trait always succeeds, and TryFrom can fail. However, it's not a "cast" -- the user calls an `into`/`try_into` or `from`/`try_from` methods.
I would be supportive of defining official ways to convert types from one to another, not necessarily casts, though. I think these qualities are important: 1. Would have failable and non-failable variants. It's nice to know that a particular conversion cannot or can fail. 2. It should be amenable to static analysis. Tools should be able to warn about missing paths for handling failable conversions, or that conversion from A to B is possible but A to C is not. I'm not sure how to technically achieve this for PHP. I don't think any casting proposal I've seen meets these characteristics, so I would personally vote no on them. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php