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

2020-02-06 Thread AllenJB
What happens if I perform array-like operations on an object implementing __toArray() from this RFC? For example: $obj["foo"] = 42; or: $bar = $obj["foo"]; (Imagine these examples are perhaps within a loop iterating a collection of objects) Which operations do and do not work? As they'd b

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

2020-02-06 Thread Mike Schinkel
> > On Feb 6, 2020 at 7:06 AM, mailto:nikita@gmail.com)> > wrote: > > While there are quite a few places where objects can be implicitly > > converted to strings (say echo, concatenation, etc), there are not > > a lot of places where objects can be implicit

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

2020-02-06 Thread Nikita Popov
On Tue, Feb 4, 2020 at 2:03 PM Steven Wade 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

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

2020-02-04 Thread Steven Wade
> I think the motivation is exactly what you said. Allowing developers more > control over how the object is treated when casted to an array - which would > include when it is passed into an array_* function. I couldn’t (and didn’t) have said it better myself. My motivation is really just to gi

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

2020-02-04 Thread Chase Peeler
On Tue, Feb 4, 2020 at 11:04 AM Steven Wade wrote: > > > Sorry if it's been said in the discussion so far, but I do not see why > > `print_r` should convert anything to an array. It accepts multiple > > kinds of types including strings, numbers, and so on, and I think > > adding this behavior to

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

2020-02-04 Thread Steven Wade
> Sorry if it's been said in the discussion so far, but I do not see why > `print_r` should convert anything to an array. It accepts multiple > kinds of types including strings, numbers, and so on, and I think > adding this behavior to `print_r` is a different thing than wanting a > standard way

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

2020-02-04 Thread Levi Morrison via internals
Sorry if it's been said in the discussion so far, but I do not see why `print_r` should convert anything to an array. It accepts multiple kinds of types including strings, numbers, and so on, and I think adding this behavior to `print_r` is a different thing than wanting a standard way for objects

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

2020-02-04 Thread Chase Peeler
On Tue, Feb 4, 2020 at 9:23 AM Marco Pivetta wrote: > On Tue, Feb 4, 2020, 14:50 Aimeos | Norbert Sendetzky > wrote: > > > Am 04.02.20 um 14:43 schrieb Marco Pivetta: > > >> I think we can't classify it as BC break, because no existing code > > >> implements __toArray at the moment, and hence it

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

2020-02-04 Thread Marco Pivetta
On Tue, Feb 4, 2020, 14:50 Aimeos | Norbert Sendetzky wrote: > Am 04.02.20 um 14:43 schrieb Marco Pivetta: > >> I think we can't classify it as BC break, because no existing code > >> implements __toArray at the moment, and hence it will not fail when this > >> feature is introduced and code gets

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

2020-02-04 Thread Benjamin Eberlei
On Tue, Feb 4, 2020 at 2:43 PM Marco Pivetta wrote: > > > On Tue, Feb 4, 2020, 14:36 Benjamin Eberlei wrote: > >> >> >> On Tue, Feb 4, 2020 at 2:10 PM Marco Pivetta wrote: >> >>> Linking (again) previous discussions: >>> https://externals.io/message/98539#98539 >>> >>> `__toArray` as a magic fu

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

2020-02-04 Thread Aimeos | Norbert Sendetzky
Am 04.02.20 um 14:43 schrieb Marco Pivetta: >> I think we can't classify it as BC break, because no existing code >> implements __toArray at the moment, and hence it will not fail when this >> feature is introduced and code gets upgraded to newer versions. > > It is a BC break because it changes t

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

2020-02-04 Thread Steven Wade
>> 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

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

2020-02-04 Thread Marco Pivetta
On Tue, Feb 4, 2020, 14:36 Benjamin Eberlei wrote: > > > On Tue, Feb 4, 2020 at 2:10 PM Marco Pivetta wrote: > >> Linking (again) previous discussions: >> https://externals.io/message/98539#98539 >> >> `__toArray` as a magic function call when `(array)` cast happen is a bad >> idea: it is a BC b

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

2020-02-04 Thread Benjamin Eberlei
On Tue, Feb 4, 2020 at 2:39 PM Steven Wade wrote: > > 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)

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

2020-02-04 Thread Steven Wade
> 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); Originally I intended the proposal to

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

2020-02-04 Thread Benjamin Eberlei
On Tue, Feb 4, 2020 at 2:10 PM Marco Pivetta wrote: > Linking (again) previous discussions: > https://externals.io/message/98539#98539 > > `__toArray` as a magic function call when `(array)` cast happen is a bad > idea: it is a BC break, and it removes one of the very few interactions > (with obj

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

2020-02-04 Thread Benjamin Eberlei
On Tue, Feb 4, 2020 at 2:03 PM Steven Wade 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

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

2020-02-04 Thread 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 re

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

2020-02-04 Thread Marco Pivetta
Linking (again) previous discussions: https://externals.io/message/98539#98539 `__toArray` as a magic function call when `(array)` cast happen is a bad idea: it is a BC break, and it removes one of the very few interactions (with objects) that didn't cause any side-effects ( https://externals.io/m