Re: [RFC - discussion] __toArray()
| From: | Steven Wade | Date: | Tue, 04 Feb 2020 13:33:07 +0000 |
| Subject: | Re: [RFC - discussion] __toArray() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108374@lists.php.net to get a copy of this message | ||
>
__toArray as a magic function call when
> (array) cast happen is a bad idea: it is a BC break,
Adding a new magic method is not a backwards compatibility break. The PHP documentation on magic
methods states:
"Caution PHP reserves all function names starting with __ as magical. It is recommended that
you do not use function names with __ in PHP unless you want some documented magic functionality.�
Any user implementing their own methods prefixed with a double underscore is taking the chance that
their code could break in the future.
> and it removes one of the very few interactions (with objects) that didn't cause any
> side-effects (https://externals.io/message/98539#98545
> <https://externals.io/message/98539#98545>,
> https://externals.io/message/98539#98567 <“Áî¥%t5ãHÆ"¨
> i†Íhttps://externals.io/message/98539#98567>)
PHP 7.4 introduced the "get_mangled_object_vars()� as a result of these concerns.