Re: Scalar Type Casting Magic Methods

From: Date: Mon, 13 May 2013 08:18:25 +0000
Subject: Re: Scalar Type Casting Magic Methods
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-67415@lists.php.net to get a copy of this message
On Wed, 2013-05-08 at 10:42 +0200, Ferenc Kovacs wrote: > 2013.05.08. 7:38, "Pierre du Plessis" <pierre@pcservice.co.za> ezt írta: > > > > The __toArray can be useful if you want to perform array functions on the > > object (E.G array_filter), otherwise I think it would be very useful if > > the This can't work. Consider <?php class C { public function __toString() { return "string"; } public function __toArray() { return []; } } $result = str_replace(new C, new C, new C); ?> Which method will be called? > > array functions can accept an object implementing ArrayAccess as well > > instead of just an array > > yeah, I also think that ArrayObjects should be accepted where array is > expected. Patches are certainly welcome, but be sure to get to every place, else it becomes an inconsistent mess :) Oh, and be consistent about return values of operations ... oh, and will $result = some_array_operation(new ArrayObject); return an array or instance of ArrayObject, if the later how will it be instantiated ... do we have to pass result factories or something to all of those? johannes

« previous php.internals (#67415) next »