Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105642 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99247 invoked from network); 8 May 2019 17:09:22 -0000 Received: from unknown (HELO mail-yw1-f51.google.com) (209.85.161.51) by pb1.pair.com with SMTP; 8 May 2019 17:09:22 -0000 Received: by mail-yw1-f51.google.com with SMTP id q185so16360340ywe.3 for ; Wed, 08 May 2019 07:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=6k6Blz0nagoOyFbgZnLVvoqq7d3FE0gdSYliiOdPS+U=; b=UEdEVZI9Bw4EHImwK6NEeLdMtWp/L0p0xLW1yeXFhYF0bEDpm0fwRTR5i2VdVhsPZZ d5cnJyblfv2y26eWYQqqgQdmmg6JRBuCaKqlRC62XylAxxAu87ea7lIO2OpN5qvKaUCj 6NWPnedzL9kw1Yqf8wU0B/A+JIO0aPHXEFYwleZVC3HVtNHD8LrWWoZfkuh01KgmWKoZ V7XMOxv4bf0CJcYi8UdwSX7n8WaEj2Lsj1r7i7N8ASple2I9gU0933hdGu2i6yEj+Ut/ WOuqNqCp/0f42GVYoJyDMmahsuohmjCbs1A7uqE1sYICrem09GIFMdgmt+MXtz5nODgQ Nhog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=6k6Blz0nagoOyFbgZnLVvoqq7d3FE0gdSYliiOdPS+U=; b=AE7PAg92Mtz293VyqGWVj0aUQo+PGfwm5YXDRH/dSSw/TdVZPiwqZfcVQlvY1sNzkp hzgEOu/nsor/ainGF8k2FKlYx7GQfq5YeBmpwVpUU824xisHsEiICmiigEt+6buQsRFu ToN7zy1yhYTYJoK+QqyXeZIP71wSPkknyXbGrQm0/73DAyBbDAGH2k77B9DuOvdITIEi QiN2nqqtsxsm7u8t2+xCQzCfYz8OOE8GQCQNLLgh/75SWFnfuD6VUxm7Q/WDZTt75iAm tw6sWGwvVOwavj30wQPZWcpYOlRUP2f0Bhj+ZrSOxxJ7J0Y1bjdf5G5ZX70BesCwd5SS PszA== X-Gm-Message-State: APjAAAUUxsUCnZiYMI9iCNAvwqMl1NimuuUN4qXR1hM0OFg4UBrDCN/y x/Sar09dQezPdJPH5AXfSOxyxRG0E/w= X-Google-Smtp-Source: APXvYqySNIblO2tt46SCfVY4N7fw75+y5B105UU72/SGJXQdR7CasXBiOl5zcr6D7bM4Lmd4ryKWBw== X-Received: by 2002:a25:8145:: with SMTP id j5mr25859587ybm.114.1557324811652; Wed, 08 May 2019 07:13:31 -0700 (PDT) Received: from [10.137.30.38] ([45.56.169.252]) by smtp.gmail.com with ESMTPSA id i13sm2692076ywg.34.2019.05.08.07.13.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 May 2019 07:13:30 -0700 (PDT) Message-ID: <81452E3F-637C-421B-A686-671234673378@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_D54F3AEE-3141-4CB1-ACDE-83397B9FE8CB" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Date: Wed, 8 May 2019 10:13:29 -0400 In-Reply-To: Cc: Internals To: Kalle Sommer Nielsen References: X-Mailer: Apple Mail (2.3445.104.8) Subject: Re: [PHP-DEV] Proposal for a RFC From: stevenwadejr@gmail.com (Steven Wade) --Apple-Mail=_D54F3AEE-3141-4CB1-ACDE-83397B9FE8CB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Kalle, > On May 4, 2019, at 12:08 PM, Kalle Sommer Nielsen = wrote: >=20 > Hi >=20 > Den l=C3=B8r. 4. maj 2019 kl. 17.58 skrev Steven Wade = : >>=20 >> Hi Internals team! >>=20 >> I have an idea for a feature that I'd love to see in the language one = day and wanted to run the idea by you all. >>=20 >> The idea is to add a new magic method "__toArray()" that would allow = a developer to specifiy how a class is cast to an array. The idea is the = same mentality of __toString(), but, for arrays. >=20 > While this sounds great and all, I do wonder about the implications it > may have on the already existing behavior of type casting an object > into an array which returns current public/protected/private property > values. While this functionality is not an ideal or by design, it is > fairly heavily (ab-)used, meaning that it is a potential BC break > without the ability to an alternative. >=20 > See this example: https://3v4l.org/ONMoi That's a great example, thanks for that. I can understand how casting = now can be as you say "abused". With my proposal, the default behavior = wouldn't change unless someone implemented the __toArray() method on = their class, which would simply give them greater control over how that = class is represented. In regards to the output of the example you linked, the same is possible = today with reflection: https://3v4l.org/Ab51l If libraries are using casting to gain insight into objects, it seems = that they could be updated to use reflection without losing any = functionality. -- Regards, Steven Wade stevenwadejr@gmail.com --Apple-Mail=_D54F3AEE-3141-4CB1-ACDE-83397B9FE8CB--