Re: Type casting syntax
| From: | Eugene Sidelnyk | Date: | Sun, 11 Jul 2021 18:26:54 +0000 |
| Subject: | Re: Type casting syntax | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115388@lists.php.net to get a copy of this message | ||
IMHO, This is suger which leads to diabetes. It adds pure implicitness
without any payback. To convert object into something else add appropriate
method.
On Sat, Jul 10, 2021, 3:07 PM Marco Pivetta <ocramius@gmail.com> wrote:
> Hey Max,
>
> On Sat, 10 Jul 2021, 11:09 Max Semenik, <maxsem.wiki@gmail.com> wrote:
>
> > I've been thinking about extending PHP's cast syntax to user-defined
> types,
> > e.g. not only (int)$foo but also (MyClass)$foo. Currently, a T_STRING in
> > parentheses is always treated as a constant - would it be acceptable to
> > hijack this syntax when used in unary operation context, i.e. "("
> T_STRING
> > ")" expr? If not, any other alternatives?
> >
>
> How is this any better than
MyThing::fromStuff(...), with
> proper tested
> and domain-specific semantics?
>
> >
>