Re: Re: [Concept] Magic Casting
| From: | Andrey Andreev | Date: | Fri, 02 Dec 2016 14:46:36 +0000 |
| Subject: | Re: Re: [Concept] Magic Casting | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97255@lists.php.net to get a copy of this message | ||
Hi again,
On Fri, Dec 2, 2016 at 4:19 PM, Alex Bowers <bowersbros@gmail.com> wrote:
> I don't see how the interface is equivalent.
>
> The benefit of this, is that you can convert types passed into a method to
> the type you expect automagically, Castable wouldn't allow that, only a new
> magic method (or reflection and user land code possibly?) would allow this.
>
A magic method is essentially an implicit interface ...
The interface itself does nothing. But when it is implemented, the engine
will know that the class constructor is public and accepts a single
parameter - thus, also knowing that it could try to do a new
ClassName($yourParameterHere)
>
> As for the limitation of only one parameter being accepted, what would the
> other possible parameters be?
>
> Since this is based entirely on the casted variable, there can only
> possibly be one variable there, the one passed into that position in the
> functions arguments.
>
>
What I meant is - you cannot cast to a class that requires more than one
dependency to be instantiated - that's the obvious limitation.
> Arguably, this feature would resolve some bugs in peoples code, because it
> can allow better enforcing of types.
>
It enables magic behavior, that's the opposite of enforcement ... If you
want to enFORCE something, you force the developer to do something, you
don't auto-magically do the thing for them.
P.S.: I suppose you've hit "Reply" instead of "Reply All"? I was the only
recepient of the message I'm quoting.
Cheers,
Andrey.