Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98556 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94192 invoked from network); 15 Mar 2017 23:27:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2017 23:27:46 -0000 Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.179 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 74.125.82.179 mail-ot0-f179.google.com Received: from [74.125.82.179] ([74.125.82.179:34519] helo=mail-ot0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/E5-38004-1FDC9C85 for ; Wed, 15 Mar 2017 18:27:46 -0500 Received: by mail-ot0-f179.google.com with SMTP id o24so37017785otb.1 for ; Wed, 15 Mar 2017 16:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=A4WqXjSW/VC1CLsxUWqz0bskQD4wvL0ZnRakmb1jQU0=; b=e15WTHGmAN4S1dDNDw8WTDa9HdFf72+hpE9tcCSN3cFO+gEzoYp3/w88w4++JxzVpq Pg+9h5CiaMSz5qCxTDH0fiIelo7l2im71bTG2VLzRLSTafU+iZvlazBG0U2crWiCazck eOc7NJFNVj+oHQkeYqV2ppt+w5PWrG7PVarGDvxAnTvo53bFp/VN/X74AmSmcTXalFpv jXdVXoIi4POgwo3Li28saIkCwcY2UEtDZA5bG7HnCbzhyaMibC0v6c19tu8R+0nV1/ly hkJJSWdh+ya4dfygbYT3CinxydvZJLHQWRGLNrQiUuD4A5mlbCl8dEBHphkQaB9Qt1YJ VM5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=A4WqXjSW/VC1CLsxUWqz0bskQD4wvL0ZnRakmb1jQU0=; b=e9j/9dhcJ+wcVjvkqYsoenj1ZNyDT3YHXGCz6Ow0zye69dM9T0oAU4JnW1npJ3Moc9 /Mg9fWjiQxh4/6521ELfk2olRb/aIOKQtHXbSb3CwtT5g+v1Q5f6qpZArRdV2c9f0FaM KN0anLtww+CLWkgfsnQ8LO9983Eo62UGd5TqKtWo3wfbYw7ivlaju7ftKxXILa7QB2m6 3UBcqq0wB9eWCtCyUKV5jP7oXxDHndB3V6Q5HLN+nJoc4961MywLxZmpE4H3zdEBWPcy 97qzmoTLlA3DDluEjl5OvVqrKVKGmRXHmfPAtTmSckE5uxNWd2Z8DDKzRqMWbX4k89UU flvA== X-Gm-Message-State: AFeK/H0BMOuqiZpGIPKNw9IAE3d1Tw6MNYvAYoTnd8L7BcPebQ/jGX7gGrPvGIt0rc/pALMInWrfipAxzjEiPA== X-Received: by 10.202.57.10 with SMTP id g10mr3168687oia.197.1489620462904; Wed, 15 Mar 2017 16:27:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.11.227 with HTTP; Wed, 15 Mar 2017 16:27:42 -0700 (PDT) Received: by 10.157.11.227 with HTTP; Wed, 15 Mar 2017 16:27:42 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Mar 2017 17:27:42 -0600 Message-ID: To: Marco Pivetta Cc: internals@lists.php.net, Kalle Sommer Nielsen , =?UTF-8?Q?Beno=C3=AEt_Burnichon?= Content-Type: multipart/alternative; boundary=001a113cdcf48aad4f054acd4a08 Subject: Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array From: derokorian@gmail.com (Ryan Pallas) --001a113cdcf48aad4f054acd4a08 Content-Type: text/plain; charset=UTF-8 On Mar 15, 2017 5:03 PM, "Marco Pivetta" wrote: Hi Ryan, I'm top-posting because I'm writing from a phone. I always do and I also stopped caring for top-posters myself because it's fairly normal, plus modern email clients deal with it. If I can write a damn mail from a phone keyboard because I don't have any better right now, then you can probably use the scroll wheel once on your pc too. I'll just say this: I'm also on a mobile device. Don't make assumptions. The BC break applies to API that accepts `object` (any object). Such API is common in library code in frameworks, data-mappers, etc. Such code would not work anymore for cases where the magic method is implemented, adding either exceptions (forcing a library-level BC break) or simply by causing the existing stable versions of these libs to be incompatible with newer php versions. I must misunderstand what constitutes an BC break. I thought a BC break was when identical code produced different results. But you're saying its a break because someone could change their code to use a new feature and break their use of your library? On 15 Mar 2017 11:57 p.m., "Ryan Pallas" wrote: On Mar 15, 2017 16:40, "Marco Pivetta" wrote: Which is precisely the BC break: such a library would now throw an exception "unsupported class X" when `__toString` is implemented. Also, such a library would break silently when this feature is implemented. Much like the already very broken `__debugInfo()`, this automatic type-cast is a giga-Joule footgun. First please stop top posting. Second bc means that if no code changes no functionality is changed. That's exactly what we're talking about. If the class doesn't change neither does the functionality. So unless classes already have __toArray they will not change in behaviour. As pointed out in answer to my question earlier a class with no code change would see no change in casting behaviour. Only if new method is implemented will behaviour change. How does that not maintain bc? On 15 Mar 2017 11:36 p.m., "Ryan Pallas" wrote: > > > On Wed, Mar 15, 2017 at 4:33 PM, Marco Pivetta wrote: > >> It's the only way to distinguish between set and unset properties. Also >> the >> only way to get all properties from an instance of an inheritance tree. > > Also, it's covered by tests that were explicitly added to prevent >> regressions on this. >> >> Same as all similar discussions before this one: need an alternative way >> to >> do things before proposing a BC break. >> >> > As mentioned in previous mails - the intent isn't to change existing > behaviour, but to provide a way for a class to override the default > behaviour. As long as those classes you are casting to array don't > implement __toArray they will behave exactly as they always have. The only > concern then, is that you might be relying on a library to not implement > that function on a class you are casting. > > >> On 15 Mar 2017 11:27 p.m., "Kalle Sommer Nielsen" wrote: >> >> > Hi >> > >> > 2017-03-15 21:41 GMT+01:00 Marco Pivetta : >> > > This is a BC break due to the fact that the `(array)` cast is used to >> > > extract property information from private properties in library code. >> > > >> > Yep, but then again that is more of an >> > undocumented-not-really-supported case afair, if anything then >> > Reflection should have the APIs to officially allow that, although I >> > am still skeptic of this. >> > Does it not through get properties? > >> > >> > -- >> > regards, >> > >> > Kalle Sommer Nielsen >> > kalle@php.net >> > >> > > --001a113cdcf48aad4f054acd4a08--