Re: Re: [Concept] Magic Casting
| From: | Alex Bowers | Date: | Fri, 02 Dec 2016 14:55:53 +0000 |
| Subject: | Re: Re: [Concept] Magic Casting | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97261@lists.php.net to get a copy of this message | ||
On 2 December 2016 at 14:46, Andrey Andreev <narf@devilix.net> wrote:
> 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.
This magic behaviour would be for enforcement, because you are now
enforcing that the passed in type is acceptable to the contract of
Collection. It can be an array, because arrays can be converted to a
Collection, and it is down to the __cast() method to determine whether that
is a suitable conversion, but it allows you to enforce a suitable parameter
is passed in. Currently, to accept bot ha Collection and an array, you
would have to not enforce anything, and inside of the method handle the
conversion or exceptions.