Re: [RFC - discussion] __toArray()

From: Date: Tue, 04 Feb 2020 13:33:06 +0000
Subject: Re: [RFC - discussion] __toArray()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-108375@lists.php.net to get a copy of this message
On Tue, Feb 4, 2020 at 2:03 PM Steven Wade <stevenwadejr@gmail.com> wrote: > Hi all, > > I’d like to officially open my __toArray() RFC < > https://wiki.php.net/rfc/to-array> up to discussion. I’ve > delayed > changing the status until I had more time to respond to the discussion, but > since it’s been brought up again > <https://externals.io/message/108351>, I > figured now is the best time. > > https://wiki.php.net/rfc/to-array > <https://wiki.php.net/rfc/to-array> > I am open to the idea of having __toArray. I just have a few questions about the RFC details. 1. print_r($object) would somehow call __toArray you say. Why would it cause a cast when nothing else is cast? I would prefer print_r((array) $person); 2. In the parameter and return type examples you should add declare(strict_types=0); so it's clear this only works in weak mode. 3. The weak point of this proposal is the by reference handling for sort et al. Counterpoint: if you pass a variable to preg_match, then matches gets converted from anything to array, so i believe by reference casting should change the original value (https://3v4l.org/XUJ5m). This is weird, but consistent. Cheers, > > Steven Wade

« previous php.internals (#108375) next »