Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102849 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92960 invoked from network); 16 Jul 2018 13:23:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2018 13:23:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.67 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.67 mail-wm0-f67.google.com Received: from [74.125.82.67] ([74.125.82.67:37064] helo=mail-wm0-f67.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/6B-39793-56C9C4B5 for ; Mon, 16 Jul 2018 09:23:49 -0400 Received: by mail-wm0-f67.google.com with SMTP id n17-v6so15907176wmh.2 for ; Mon, 16 Jul 2018 06:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:cc:from:message-id; bh=8vZvLxpLPX3b8ZRjEoJHX0QC+afgbkxGr8d/10Eoy5U=; b=Gaomp7vr9Jmv3X1Gso9idgZXhdw4ELhIiu3gkbmlQbtkk7nGHKCI3zWlE4EfxNGEzC HvMpKAnBunuHcZlygtYzdfJSnoy3bgY0tnNQtqbl0bPCmxitdhuKP1wtPjYzY9KyKnar J+ltlnLXIxVEYdnOZtpZemBd0GR9iPw3bNY1Z0HweM/qghi+ssk52LzUsWs+t2kA2ivw TYpcK6ciaB4fUogzYaqhc8i9/D40zeK3McODgbb8wroyeSoGvs4Xkshhe2d1yn460ZPV PJBI/IpbbkVvl2GuWzCoDUQ/KMhhEQzyYIqHhiYoKJDGelTgb1k70HfLXDtjPvaJSLXc 5v9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:cc:from :message-id; bh=8vZvLxpLPX3b8ZRjEoJHX0QC+afgbkxGr8d/10Eoy5U=; b=n11yfJE4v+MU9cJAciF9KJClhA4xYLRCeV5D3FvZKiZ9eudOboUug6vXqTCmMNyWRY E7V1tZmNn2MDBXcmx8X448xV5bc/0VpUQyboWgEEA8520Jn0lZxxBJK/WAxHhGS9mO85 LzyLfexOybpUz266G3/sc8VqSHQgOtdFCZzMV30Lrgi4iMPnNE9q4KRFP+n3+WH9AcRI M0EBLddxxB8chpK5JX3FtDMJfa2hECc7SHjMaXw9qvohtLQNuhkAzI/CMLaaI8kwWw1Q rnsSIBiHtS76N/lZ9ir+QWThwwtsrPFimTw1BHEtWHJTMpg/Y3z4MaQ7l5Iod5yGuyNU omCQ== X-Gm-Message-State: AOUpUlGhhPE1TXKfBUatyakePKcjWG15dVPRkg7NF49NVt+52xYs0+YU 7yLDSY8UGCi6L81iNos8Z9c= X-Google-Smtp-Source: AAOMgpdm+meWz3VfzuJD6a9VILheYk/wElJcAbAiqJOvBurr1tlUgik2ASoV2ExgiWgajpl/pwxJBA== X-Received: by 2002:a1c:6fdd:: with SMTP id c90-v6mr9591952wmi.16.1531747426652; Mon, 16 Jul 2018 06:23:46 -0700 (PDT) Received: from [10.7.50.202] (188.29.165.156.threembb.co.uk. [188.29.165.156]) by smtp.gmail.com with ESMTPSA id q17-v6sm32515741wrr.7.2018.07.16.06.23.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 06:23:46 -0700 (PDT) Date: Mon, 16 Jul 2018 14:23:43 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <8916EC21-D368-40F8-9ABD-CE0C04A73539@gmail.com> <0AA3251E-A0D8-492E-AEAC-3B2FBBFDB944@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----E6SDFEVXG8HHHHWCQ7FWBK9DM9TTIG" Content-Transfer-Encoding: 7bit To: Dan Ackroyd CC: PHP internals Message-ID: Subject: Re: [PHP-DEV] Non-nullable properties From: rowan.collins@gmail.com (Rowan Collins) ------E6SDFEVXG8HHHHWCQ7FWBK9DM9TTIG Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 16 July 2018 13:00:57 BST, Dan Ackroyd wrote: >On 16 July 2018 at 09:43, Rowan Collins >wrote: > >> There's no contradiction here; throwing an error when a >> property is *read* is not the same as enforcing that it always has a >valid value=2E > >That's true, but claiming the RFC just 'trusts' the users to >initialise them is a miss-representation of the RFC to me=2E The RFC >catches the mistake if the programmer fails to initialise the variable >then reads from it=2E Perhaps a better wording is that it requires one user to trust another use= r: the mistake that leads to an unitialized property is the responsibility = of the author of the class, but the error only appears when the object is u= sed, which could be in a completely different library=2E >> If not, the object created would not be fully initialised, > >This is always going to be the case, unless you're proposing to >deprecate ReflectionClass::newInstanceWithoutConstructor =2E=2E=2E=2E whi= ch is >going to break a huge number of applications=2E It only needs to be banned (or modified) *for classes which claim their pr= operties are non-nullable*=2E Or, don't introduce non-nullable properties, = because they can't actually be enforced=2E > For me >it is the equivalent of this: > >function foo() : int { > return "five"; >} > >This gives an error when the code is run, not when the code is >compiled It's not about run-time versus compile-time, it's about when the error is = raised=2E In this case, it's raised when the return statement is executed= =2E The equivalent to the proposed behaviour would be this: function foo() : int { return "five"; } $foo =3D foo(); // runs OK, but marks the variable as invalid // =2E=2E=2E Many lines of code later // $foo has not been touched so should be an integer $bar =3D $foo + 1; // Error! Sorry, somebody messed up a return value some= where, it's now up to you to figure out where >That would only be a problem in production if you don't run that code >at all in development or in test=2E=2E=2E=2E If you are going to write tests to see if all your variables are being ini= tialized correctly, then you don't need non-nullable type hints, you can ju= st assertNotNull on each property=2E But again, the user writing those tests is not the user relying on them=2E= You are asking users of a library to trust that the library has appropriat= e tests=2E Regards, --=20 Rowan Collins [IMSoP] ------E6SDFEVXG8HHHHWCQ7FWBK9DM9TTIG--