Re: Add __toArray() method to objects that would be called on cast to array
| From: | Andrea Faulds | Date: | Thu, 16 Mar 2017 09:16:24 +0000 |
| Subject: | Re: Add __toArray() method to objects that would be called on cast to array | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98565@lists.php.net to get a copy of this message | ||
Hi Benoît,
Benoît Burnichon wrote:
Looking at the manual http://php.net/manual/en/language.types.array.php#language.types.array.casting , it seemsI'm not sure what specifically you see to be the problem, but I think it might be worth directing you to my RFC which relates to this: https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts -- Andrea Faulds https://ajf.me/ArrayObjectclass does not comply to array casting because integer public properties could also be retrieved. Some tests showed that regular class always have string keys even when a `$key = 0; $this->{$key} = 'avalue';is called. In this case,var_export((array)$object);` returnsarray('0' => 'avalue')(Notice the quote around key 0 - https://3v4l.org/6QW70)