Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98565 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28422 invoked from network); 16 Mar 2017 09:16:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2017 09:16:35 -0000 X-Host-Fingerprint: 137.50.185.121 oa-edu-185-121.wireless.abdn.ac.uk Received: from [137.50.185.121] ([137.50.185.121:1826] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/B9-38004-CE75AC85 for ; Thu, 16 Mar 2017 04:16:28 -0500 Message-ID: <74.B9.38004.CE75AC85@pb1.pair.com> To: internals@lists.php.net References: Date: Thu, 16 Mar 2017 09:16:24 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 137.50.185.121 Subject: Re: Add __toArray() method to objects that would be called on cast to array From: ajf@ajf.me (Andrea Faulds) Hi Benoît, Benoît Burnichon wrote: > Looking at the manual > http://php.net/manual/en/language.types.array.php#language.types.array.casting > , > it seems `ArrayObject` class does not comply to array casting because > integer public properties could also be retrieved. Some tests showed that > regular class always have string keys even when a `$key = 0; $this->{$key} > = 'avalue';` is called. In this case, `var_export((array)$object);` returns > `array('0' => 'avalue')` (Notice the quote around key 0 - > https://3v4l.org/6QW70) I'm not sure what specifically you see to be the problem, but I think it might be worth directing you to my RFC which relates to this: https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts -- Andrea Faulds https://ajf.me/