Re: Proposal for a RFC
| From: | Paul Jones | Date: | Sat, 04 May 2019 16:10:45 +0000 |
| Subject: | Re: Proposal for a RFC | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105592@lists.php.net to get a copy of this message | ||
> On May 4, 2019, at 11:08, Kalle Sommer Nielsen <kalle@php.net> wrote:
>
> Hi
>
> Den lør. 4. maj 2019 kl. 17.58 skrev Steven Wade <stevenwadejr@gmail.com>:
>>
>> Hi Internals team!
>>
>> I have an idea for a feature that I'd love to see in the language one day and wanted
>> to run the idea by you all.
>>
>> The idea is to add a new magic method "__toArray()" that would allow a developer
>> to specifiy how a class is cast to an array. The idea is the same mentality of __toString(), but,
>> for arrays.
>
> While this sounds great and all, I do wonder about the implications it
> may have on the already existing behavior of type casting an object
> into an array which returns current public/protected/private property
> values.
I find it easy to imagine that objects not implementing __toArray() would continue to exhibit that
behavior.
--
Paul M. Jones
pmjones@pmjones.io
http://paul-m-jones.com
Modernizing Legacy Applications in PHP
https://leanpub.com/mlaphp
Solving the N+1 Problem in PHP
https://leanpub.com/sn1php