Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102856 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9400 invoked from network); 16 Jul 2018 16:09:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2018 16:09:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 64.147.123.21 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 64.147.123.21 wout5-smtp.messagingengine.com Received: from [64.147.123.21] ([64.147.123.21:52287] helo=wout5-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/FD-39793-553CC4B5 for ; Mon, 16 Jul 2018 12:09:57 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 67CC533A for ; Mon, 16 Jul 2018 12:09:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 16 Jul 2018 12:09:54 -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=C85+vUzl4/bxcAa90ctZqmzVqV4x2 Euz3Zngx04dPUo=; b=VhkASpc40EIdbJdyuRdW6ONJM7WrO209rODHA+9eIocX6 GA6DlCEeDcSyTrh/NAcwxeoykLl7fOMkrKVz9ICaUYPSWqMUD3ztZZ6z+FFpZ39N iSmAQE6r4orpvKYqv68RsIkRvnucsJiB2dWTA+hGlhjpWzdBXOHao/HHspgBNv+L ZyKaS3EykdsdBC4zDQ4DuzPIM5JW9ME1lfwV9+TbtEMSRWoxuq6Bqi5Nwdl8h33E bvLFhN1SFOpgt0CVcx+0VZZ2aLKIVyx3skEe7PX+q+ucVRB+bA7HUwIzmvT9viWd aFwjcEphH1w2+TcLYSzAMGwqa7YFqujc0ADzFw24w== 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 951D1E473B for ; Mon, 16 Jul 2018 12:09:53 -0400 (EDT) To: internals@lists.php.net Date: Mon, 16 Jul 2018 11:09:52 -0500 Message-ID: <1832302.prXWr4o048@vulcan> In-Reply-To: References: <8916EC21-D368-40F8-9ABD-CE0C04A73539@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart14873677.nTEbJEA0H0"; micalg="pgp-sha512"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV] Non-nullable properties From: larry@garfieldtech.com (Larry Garfield) --nextPart14873677.nTEbJEA0H0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Monday, July 16, 2018 9:55:31 AM CDT Rowan Collins wrote: > On 16 July 2018 at 14:28, Marco Pivetta wrote: > > These don't really need explicit tests in most cases, but rather static > > analysis (currently happening via docblocks). Static analysis tools like > > vimeo/psalm already pick this up. > > Then why do we need the type hints at all? > > > I'd even be happy to get type hints that only have effect on > > `ReflectionProperty#getType()` as a massive improvement over the current > > situation we've monkey-patched us into, but the patch is indeed consistent > > with PHP's current state. > > I disagree that it's consistent. It introduces an entirely new kind of null > reference ("declared but uninitialised"), which will require *more* careful > checks than forcing the value to be initially null, and will undoubtedly > further annoy those who already claim that isset() is broken (the RFC > doesn't even mention it, but I presume uninitialised properties will return > false from isset(), but throw an error from is_null()). > > If all typed properties require a valid default value, the patch is > simpler, errors are raised at a line where you can fix them, and the > language remains consistent - if you're promised a Foo, you get a Foo, not > a "whoops, why isn't there a Foo here?" error. > > > Regards, This is a possibly highly stupid idea, but I'll throw it out anyway so that it can at least be explicitly rejected in that case... Since Swift was mentioned before as a good example, what about borrowing from Swift? Viz: class Foo { protected Bar $b; // This runs before __construct, is not inherited, and cannot // ever be skipped. If this method exits and any property is still // value-less, TypeError immediately. protected function __init() { $this->b = new Bar(); } public function __construct() { Behaves as it always has. } } That's similar to the "initialize" flag inside the constructor, but splits it off to a separate method that is devoted to just that purpose; it therefore has no parameters, ever, and if you want to initialize an object property based on a constructor argument then you must either make it explicitly nullable or initialize it to a dummy value first. Which... I realize may not work well for service dependencies as the dependency chain could get deep. Of course, that use case is generally a protected property not publicly accessible, so making it nullable and trusting yourself to populate it in the constructor is likely "safe enough". Thoughts? --Larry Garfield --nextPart14873677.nTEbJEA0H0 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/GXfY8v0YwFBp4MMKwDFxYXcFAltMw1AACgkQ4MMKwDFx YXfZFwf/dh69UTIv3weiAS9u5zlTAXU54IuHUlEjbfPyDEX3eBdJoFPSsYqwMYUC GMI+5/miBog5l1iURWnvlF2551L2cmNAixKrLhOzO9G/df+e+qhQBoIKLZR4J/aL +q3PI8D6A+T8T9hKUdZroIqK/5mXcYrgpzjBFls0qwr+hGvo2twWbkM5KeiPCPhT AqoB13Jo4+VDHDVS7Cp45OqGiiw3i4RTTT+7lYolQgDaI3iHdo+ihONutjpxDlwW 3JVCJ82dbyOM4MshRYXBfqzKI/Bc4zQJ5fyRrkixMXq0a+a98vX5biZGQPJl4ZQ5 rADIgFtY4yFea4RrYq0qu6EVIehfxQ== =UWG2 -----END PGP SIGNATURE----- --nextPart14873677.nTEbJEA0H0--