Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103184 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48965 invoked from network); 19 Sep 2018 21:36:44 -0000 Received: from unknown (HELO mail-it0-f49.google.com) (209.85.214.49) by pb1.pair.com with SMTP; 19 Sep 2018 21:36:44 -0000 Received: by mail-it0-f49.google.com with SMTP id h3-v6so9453053ita.2 for ; Wed, 19 Sep 2018 10:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=CThFq3AsLTrTqD66MYyGXmWXrDcoySg3sPJbAL9tH/I=; b=Sn9JiATcKVwJ2vFOlHfdJRC9bjieRijuib+Gd2ncg7TRxnZU5XlBZubACil02i9eqJ xjx8zpGPob8ZoFJXh4zMzNBzbh1di2lc+6tYIKayNwZaIMnySrXNVOcBiOzaVQLbJwl0 l1nTF1Zm8N8T3LFGzQwqfHP9tnos4dvi2ITgl7Jbk13gwXYCyp3uHyapXIeQUrvEeRlo 6wumX54Su7a2W+qjGEbWaW+41nfEolPIPieQQL1uE7FWV0TUFYNYVERFwZJ5Cx8SvO0c s5S0ACIq1Onv0vwT5MjXEJTEbcCaEwEpbQPRwGRLjcClgllBfCethrRbfIzjJ1J6fYfK 1Qqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=CThFq3AsLTrTqD66MYyGXmWXrDcoySg3sPJbAL9tH/I=; b=Z3H4aTPMfMzKUuVHQtQtW1ae2XXv+dj+ZwdltS6QEr10x+aRcYFagcstA3Vs+80k3q ms0diN+qpcn8zYZ24ztZjjvSpFl8MrUOkIZf2SfE/TXO1yeAMg6Xc+S9J6CbVTFYyoqQ A1pdIe3LXT0kXOYK/1r18NtcM2ZzqHoozqI0+jfSAfw9VnldiKnHR+SJMeS15yrHbvNm RRXJxZJaHNQ2/aYuG1XFXMFMJL9P40f5PM599ehzpPUEEAdrV/T6msBYbPHHx3h4Ow/j eIOZhiRYpK8QpQGXtR4L6RnE0O+37cGmMjHjAF51d/iNhMo0PxLRJtSJWlSPVhH1Mgf+ 3PSQ== X-Gm-Message-State: APzg51ASyJBfN+kBSxWhmxvOxaOaJBpgd7+MRfFC5IF3zIDqqYVhwHrd BbLNlTMc9aicPUixU1w7JkRgFefdtqrUYADryJzd4kGE X-Google-Smtp-Source: ANB0VdbWEmaMlolZgAGkFWJhqIjkxYYQHXPHLI8+G61g9s6i8t1s48yX3RTj/BSctEvpqS153WP7Ya1V28YGY0LetG0= X-Received: by 2002:a24:1355:: with SMTP id 82-v6mr23262767itz.74.1537378989335; Wed, 19 Sep 2018 10:43:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 19 Sep 2018 18:42:57 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000008b6e3205763cf0a9" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: rowan.collins@gmail.com (Rowan Collins) --0000000000008b6e3205763cf0a9 Content-Type: text/plain; charset="UTF-8" On Wed, 19 Sep 2018 at 16:57, Levi Morrison wrote: > I posit that this code: > > class Foo { > public Foo $foo; > } > > Is superior to this code: > > class Foo { > public ?Foo $foo = null; > } > > If after "initialization" that `$foo` is guaranteed to always contain > an object of type `Foo`. Yes, IF it guaranteed; but the current proposal offers no such guarantee. Whichever of those definitions is used, the following code may fail: function expectsFoo(Foo $foo) { assert($foo->foo instanceOf Foo); } > The reason is simple: for the actual lifetime > of the object the former correctly states that it will never be null, > while the latter opens up possibilities of it. It correctly states that it will never be null, but it incorrectly implies that it will always be an instance of Foo. It's not even true that *once initialised* the property will always contain a Foo, because (if I understand it correctly) it is also allowed to call unset() on a non-nullable property at any time. > That is, the former > provides *better* support for non-nullable types. > The property is only "non-nullable" because we have invented a new state, very similar to null, and called it something other than "null". > To prevent all forms of initialization errors we would have to do > analysis at the initialization site and prevent dynamic behaviors in > that region. For now I believe such things are better left to static > analysis tools than the engine. > I agree that this is a hard problem, but I don't agree that this decision is being made "for now". If we allow "non-nullable but uninitialized" properties now, it will be extremely hard to change their behaviour in future. My request is emphatically not to reject the entire RFC until this is solved. It is to say that "for now", all typed properties must be initialised inline to a valid value; and by implication, that a non-nullable object hint cannot be used. Regards, -- Rowan Collins [IMSoP] --0000000000008b6e3205763cf0a9--