Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91873 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65104 invoked from network); 22 Mar 2016 21:22:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2016 21:22:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.47 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.47 mail-oi0-f47.google.com Received: from [209.85.218.47] ([209.85.218.47:35051] helo=mail-oi0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 55/C6-30596-287B1F65 for ; Tue, 22 Mar 2016 16:22:12 -0500 Received: by mail-oi0-f47.google.com with SMTP id w20so137121189oia.2 for ; Tue, 22 Mar 2016 14:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to; bh=Xp94kWWjADQoH82XVQZwgCiP2iy6NJZdqc6wc8ZfbOY=; b=WfiGlxL03yZ5qegvUcjEzcet5cnYUi5SbJVyB3maF/+4mvsrdq6kmdemicwb8c1eLp SVM9GkRb6293ZKf86z2IVTSu4bToJS2c/krO7DSgPe9xIaJ+1rwp7Sg+CYAkl5c+bd3/ mIMQMYrcKRpaDfWBjr6wG4+Ql341btmgdlCGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=Xp94kWWjADQoH82XVQZwgCiP2iy6NJZdqc6wc8ZfbOY=; b=ZlJOUonvjWRIvtIpBSYOv5ALhJF3xhb47myUkOXC4AE4gR9LQgFsBL0c6JqIur1WNy UGBuyn/6SXjKEO/VFjar2K3bRptJIO/o1YN2VGV7jj0xlg6iuXcpiW4EB72YRKpq9v2S elyKtxYnAqM28ym8iEO8pBWRqmW69Ipd/BbO/zhowF3C1aCd9U3MWbrW9oyQ3r7VVwhj eQ0wJsCMJjgG5OzE5zJp9+p9FlhT3d/gv/5IASrXx/VTJIUzR3aVi2mIe7X4dIPl4LWB +q2Ul5kHsCjvZsvZ4Gfn47rGa0ekj6SdX2ZKwGwS6PCvAFdgsygP7EDPC2N4qZ6puRsn 6ICQ== X-Gm-Message-State: AD7BkJJvygaTeLK2iUTTxMgkKRBWlJbipGeW41GPwYOmqQLTTIM4q1pT3NXmk2SS64cI4LStVUiZ7HK7mylS6g== MIME-Version: 1.0 X-Received: by 10.157.0.39 with SMTP id 36mr4486774ota.191.1458681728295; Tue, 22 Mar 2016 14:22:08 -0700 (PDT) Received: by 10.202.175.74 with HTTP; Tue, 22 Mar 2016 14:22:07 -0700 (PDT) In-Reply-To: References: <1458149992.3969.2.camel@kuechenschabe> <1458151531.3969.8.camel@kuechenschabe> <1458153695.3969.16.camel@kuechenschabe> <3F.70.02405.6803BE65@pb1.pair.com> <56F01545.8080008@gmail.com> <56F14572.701@gmail.com> <56F15EF5.80006@telia.com> <56F16023.1010002@gmail.com> Date: Tue, 22 Mar 2016 23:22:07 +0200 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=94eb2c08ca7a417df9052ea9ce6e Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: narf@devilix.net (Andrey Andreev) --94eb2c08ca7a417df9052ea9ce6e Content-Type: text/plain; charset=UTF-8 Hi again, Apparently I misunderstood the parts of the RFC that I was most concerned about (isset() and what causes magic method calls). Joe clarified most of it for me elsewhere and so now I'll be answering my own questions here, in case that helps anybody else: On Tue, Mar 22, 2016 at 9:26 PM, Andrey Andreev wrote: > Hi, > This mail turned out to look quite a lot like a rant - sorry about that. I > can assure you I am genuinely looking for answers on the questions that > follow ... > > https://3v4l.org/Lq5dA/rfc#tabs (an example is from the RFC itself) > > It doesn't make sense to me, for numerous reasons: > > 1. Why are any magic methods called for public (and already declared) > properties, especially from inside the object's constructor? > 2. Even if there's a sane reason for that first point, a __get() call may > not even attempt to access the property in question, so why is its return > value taken into account? > Apparently, after you call unset() on any kind of property, magic methods will be called the next time you try to access it - seems quite strange to me, but not this RFC's fault, so ... > 3. Why does unset($this->bar) call $this->__get('bar') and not > $this->__unset('bar'), like it happens for all properties currently? > It doesn't. The comment on line 7 makes it look like that's the case but actually tries to say what I just did above. > 4. Furthermore, why is unset($this->bar) valid on initialized properties, > but not on uninitialized ones? > > It's valid in both cases, I've misread the error message line. > I also still feel that completely preventing a typed property to "return > NULL" in any shape or form is a way too opinionated decision ... > > I can understand disabling explicit NULL assignments. And I don't > particularly like it, I also understand throwing TypeError for direct > access on an unitialized property: > > class Foo { > > public int $bar; > > } > > $foo = new Foo(); > > $this->bar = null; > if ($this->bar === null) {} > > // ^ I agree, both of these SHOULD throw TypeError > > However, I see no reason why this shouldn't work: > > class Foo { > > public int $bar = null; > } > > $foo = new Foo(); > is_null($foo->bar) && doSomething(); > > That's no longer a question of should uninitialized properties be > accessible; it's explicit - the developer writing this *wants* the property > to have NULL at least as the default value. > With all the "consistency" arguments thrown against virtually all > proposals so far, why is this one inconsistent with typed parameters? > Sure, the RFC half-addresses this question by saying that it intentionally > doesn't touch on the subject of nullability because of the eventual union > types feature, but that feature is not even officially proposed yet. > Theoretically, it may not ever change its status from "Draft", let alone be > accepted, but even if so - I don't see it disallowing function foo(int $bar > = null) {}, so does it apply here? > > I still disagree with this, but it seems like I'm by far in the minority. > And finally, and most importantly - throwing a TypeError even on an > isset() ... that's not even a function call. > Some may prefer to think of isset() as if it was an inverted is_null(), > but we all know it's not quite the same and it doesn't emit notices for > undefined variables. So why should it throw TypeError for properties? Why > can't we at least have a way to *check* if a property was ever initialized? > > I've misread the error message line for this one too, which is good, because I was most concerned about being able to do an isset() :) Sorry for the noise. > Cheers, > Andrey. > --94eb2c08ca7a417df9052ea9ce6e--