Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103223 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15215 invoked from network); 22 Sep 2018 00:53:12 -0000 Received: from unknown (HELO out1-smtp.messagingengine.com) (66.111.4.25) by pb1.pair.com with SMTP; 22 Sep 2018 00:53:12 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id DEF8421BC4 for ; Fri, 21 Sep 2018 17:00:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 21 Sep 2018 17:00:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=R8wF29iIkhT3ll5gZsQOa/aqWdbNu L7+8/veJhOKEY4=; b=mBNU5H3BNkAe2njH8qYH/dnDdvVRAD0uw6h9Oni2phfU/ rZg41uwyBbbDVZglVdlbE65gKPqfWS76NDQZQFmcXsO+h8fPxdSHvEi0NAATG2T8 3DVD++HGaE/n8LiI7eSVVn6ra7NdIO+Wd/mY6gx3rwupUWjImFnZEdflUMvsDZ4i zcrgLmmc393/NFsI7CKF4SNoINcXwiFzatYijxHgpIJ6FA0xWUBZbhbeZZr+Cph9 tSI0/c97tzwalN4tK4ikFoKECt3GczupTqP1k/ZvjJHgzho4SRZAqcc+zaz5tFvC GE4KDINOcmVvK92oPP2G6c5fGt5IOfzEoCqi9Zymw== X-ME-Proxy: X-ME-Sender: Received: from vulcan.localnet (216-80-30-152.s3222.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com [216.80.30.152]) by mail.messagingengine.com (Postfix) with ESMTPA id 4D92AE462B for ; Fri, 21 Sep 2018 17:00:09 -0400 (EDT) To: internals@lists.php.net Date: Fri, 21 Sep 2018 16:00:08 -0500 Message-ID: <5016361.XPtX2qLQRi@vulcan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3991336.bncjmcWpG4"; micalg="pgp-sha512"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV] [RFC] [VOTE] Typed properties v2 From: larry@garfieldtech.com (Larry Garfield) --nextPart3991336.bncjmcWpG4 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Friday, September 21, 2018 10:25:50 AM CDT Rasmus Schultz wrote: > On Fri, Sep 21, 2018 at 10:24 AM Lester Caine wrote: > > Ignoring the debate on uninitialized/null ... not all objects ARE > > invariant > > hence nullable types. > > > and there are very good reasons for not setting values for > > everything, but it seems that these types of object are deemed to be > > 'bad coding' where in fact the simply have elements that yet to be > > 'initialized' if at all for this instance of the object. > > that's what nullable types are for. > > > The constructor > > simply creates those elements that need to exit and does nothing with > > the holders for elements that have yet to be populated ... they stay null. > > hence nullable types. > > the point of using type-hints on the properties of a class is to describe > the invariant state of that class - if the state of an instance of that > class is not what the class itself prescribed/promised at the time when you > return from the constructor, what's the point? > > the only difference between using nullable vs non-nullable property > type-hints then, is whether you can set them *back* to null after setting > them to value - but it's okay for them to return from the constructor in > a "null-like" state? > > this doesn't provide *any* additional guarantees: > > class Foo { > public int $bar; > } > > $foo = new Foo(); // invalid state allowed > > $foo->bar = 123; // valid state > > $foo->bar = null; // invalid state NOT allowed?! > > Have the effects on the null coalesce operator even been considered? > > $bar = $foo->bar ?? "what"; > > Is unintialized "null-like enough" or will this trigger an error? > > Extremely confusing. > > Type-annotations are essentially assertions about the state of a program - > if you can't count on those assertions to be fulfilled (which you > can't if they're > not checked at the time of initialization) then they're not useful. > > The bottom line for me is that property type-hints were supposed to make > my programs more predictable, make the language more reliable. > > Instead, we've introduced a whole new kind of uncertainties, new ways to > write unpredictable code, a new kind of null that makes the language even > more unreliable. > > In terms of reliability, it's actually sub-par to hand-written accessors. > > Shorter syntax, reflection support, great - but ultimately at the cost of > reliability and predictable state. > > For one, what good is reflection, if it tells me I can expect a property to > be an integer, and it turns out it doesn't have a value after all? > > If you want horrible code with no guarantees, there are plenty of ways to > do that already - you don't need property type-hints for anything more than > mere convenience in the first place. Rasmus, would the "checkpoint validity checks" I suggested in another branch of this thread ameliorate your concerns, at least to some degree? I think they're as good as we'd be able to get, given the nature of PHP, but should at least cover the most common cases. --Larry Garfield --nextPart3991336.bncjmcWpG4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE/ph/GXfY8v0YwFBp4MMKwDFxYXcFAlulW9gACgkQ4MMKwDFx YXfWJwf8CVtBmh4U8pofsxfIZyg0Rt9Ubf0ZYXEHunM65uDCo4wp4S8PVLBstRLM 9+fzMbyBuFQOC3CvbuhUf70k4tddZ1t2nIw7a+t40R4dfwDlJg1PwZkkYhv/b1HF 12fxXXBZITmYQy+LE7m+awliTiKhjz4NAI4iAvAERqQO88u810o2hJuGbg6x5CKi S1Yn8tsGcsEq+zvMPvy/GX4NFyV3zVeD3C4rz8LeNTfOR5aeBMkjM9gAFapRJ8Mn 4NS+p+WqkhrLDgFr9TmClmPSPrEeVVnCYexv54s7GQ9/CbdKzVWoIrtelRjUG1qs +l387QBHv8WKsofIr/b1azUkX/1NVg== =2Fi0 -----END PGP SIGNATURE----- --nextPart3991336.bncjmcWpG4--