Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98555 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92005 invoked from network); 15 Mar 2017 23:03:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2017 23:03:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.169 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.216.169 mail-qt0-f169.google.com Received: from [209.85.216.169] ([209.85.216.169:36532] helo=mail-qt0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/85-38004-348C9C85 for ; Wed, 15 Mar 2017 18:03:32 -0500 Received: by mail-qt0-f169.google.com with SMTP id r45so24993307qte.3 for ; Wed, 15 Mar 2017 16:03:31 -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=zcsAKQcNDjDZ85658XzQCy2GlmkXiiB2SuC05kRlfj0=; b=rUQQRz/NffXJNsfTvTbbrHeWtHu9qmo8BbFOh5JukI31IqK5OkGVj9ustbSuis56p1 aRdMo3VCCzYVKFh8QhtymKKKbO1KFBkHM+y4ad53ZUHPujiksWI2v0eUZwGhUpfKcNOa rh+GG8A5d75jjzD27cL9142zDus58+OY3rOtNwANhj4KOYTGS/96jlTvfL2Q6gkvAU7e cCJ9HpaFk39hf+uR3VIh6jqFvXT9hNzhrRpxxO7WW382E2/qjYy778UvZ+rEaO+SDqqm Jq6gTSXTzX+g4AG3ZMFSH+SmDs+FahxksGTxHXB3RShbZ3zBKf8YJsLWZOJ+304asMfJ fLcA== 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=zcsAKQcNDjDZ85658XzQCy2GlmkXiiB2SuC05kRlfj0=; b=b5UmMRTyRqVZAoZdb55dvQDmEmLxrgOWHDYk6A0RA2vpRBRBLckK8MgAr01V/I1XoT ZGviG1Io4CyTslN55IHWSvTyKwlD4TcRC4O0+MvI58/SC1xI+bAqp7rR4rHXZ5G+ZUMg hbxY1JZPamUZfkLRKzMbXJBS+/orzc8Zn5LFQRpW1/+ZiD/RByNbh6J/oEEAv34GMGHB a4KEiX1HBMRE0atXjGPldMYlE5KsV6JWBhqpklOZongbLGo11NmZKLk6OIMtd7NLCpi7 JEtnLi4LJEg+/JcRHqMmTZvPIrUBNPylzGZPDzH9PgyA/9O6nTD5IZ67q3TyIlslG4UB satA== X-Gm-Message-State: AFeK/H1OfSuO3i3Ksk/MdKNQ0c0/99Lu2WyQgZYCFQXt3om4tLZ7ENkq1fSoXj3j+RXg/b19czSl/SWJb1ReGQ== X-Received: by 10.237.43.162 with SMTP id e31mr5903612qtd.189.1489619008862; Wed, 15 Mar 2017 16:03:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.44.70 with HTTP; Wed, 15 Mar 2017 16:03:28 -0700 (PDT) Received: by 10.237.44.70 with HTTP; Wed, 15 Mar 2017 16:03:28 -0700 (PDT) In-Reply-To: References: Date: Thu, 16 Mar 2017 00:03:28 +0100 Message-ID: To: Ryan Pallas Cc: =?UTF-8?Q?Beno=C3=AEt_Burnichon?= , Kalle Sommer Nielsen , internals@lists.php.net Content-Type: multipart/alternative; boundary=94eb2c0671eedfcd6c054accf3d7 Subject: Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array From: ocramius@gmail.com (Marco Pivetta) --94eb2c0671eedfcd6c054accf3d7 Content-Type: text/plain; charset=UTF-8 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. 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. 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. >> > >> > >> > -- >> > regards, >> > >> > Kalle Sommer Nielsen >> > kalle@php.net >> > >> > > --94eb2c0671eedfcd6c054accf3d7--