Re: [PHP-DEV] [RFC - discussion] __toArray()

This is only part of a thread. view whole thread
February 4, 2020 13:33 (Steven Wade)
> `__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 ( <>, <>)
PHP 7.4 introduced the "get_mangled_object_vars()” as a result of these concerns.