Re: Class cast
| From: | Benjamin Morel | Date: | Wed, 25 Mar 2020 17:36:03 +0000 |
| Subject: | Re: Class cast | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109304@lists.php.net to get a copy of this message | ||
>
> Currently PHP supports generic castings like (string), (int), ... maybe is
> time to allow class castings like (ToClass) $fromObject?
I've proposed something similar a year ago:
https://externals.io/message/105332
My intention wasn't to create an object from a scalar, nor was it to limit
to a class' methods & properties (hardly possible in PHP), but to ensure
that the value is an instance of the given class/interface, or throw an
exception.
My proposal wasn't so well received, though.
— Ben