Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102825 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74684 invoked from network); 14 Jul 2018 18:29:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2018 18:29:45 -0000 Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.208.170 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.208.170 mail-lj1-f170.google.com Received: from [209.85.208.170] ([209.85.208.170:41614] helo=mail-lj1-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/1F-39793-6114A4B5 for ; Sat, 14 Jul 2018 14:29:42 -0400 Received: by mail-lj1-f170.google.com with SMTP id y17-v6so22017535ljy.8 for ; Sat, 14 Jul 2018 11:29:42 -0700 (PDT) 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:cc:content-transfer-encoding; bh=RZguxQslOxxpH8ws1K9WG+iMQwfSQvoU0bab6EAr2XE=; b=Glwt797t8OhAoe73Upt0psO8s52wO4UnFRiDgxKq9pKL4OxfSVeQxhpS4khuQC1QtS KQ3y7NxzH4im92IMVTpLb63SazbnAw8r+JUdwp+IzSvaAeTliC74wgEMwqmmZvrgAXmJ 2amJb8lhAzodrxJ6+EGXwmaJM+59xnYba9J8RVGyEyCQsNtFvAI0yvt2rC45BqgenbPe rAGIB7L6ZMoNrM1tTfCIXF9lYvGLqbED5tYXe97/czeZM2A8PjLmH7C3am5CofoAfW5Q yHKdGEyZynyLBfjBONn1CNhUmtfXHD72krquqAZzf4TEhTCQ+AB2v+MqaCEaN9H+sURi K9Mw== X-Gm-Message-State: AOUpUlGksdw+jKGHMTB0Y09VgZWiSXlnQBBuX2FZ1Vxq2cCK7Qu1Lb7h MdpsJbAhp3IF2geDDgrvHBsPrt1wiimqYiP1zlA= X-Google-Smtp-Source: AAOMgpcryHxl3FgpKSol4u0BbHc82mfkCiMht/22v9wP0fM2gi3SLMjVjad+dzHLB1k7tRDEzAGpxUhrkNsHXMhEcKM= X-Received: by 2002:a2e:7815:: with SMTP id t21-v6mr5925923ljc.61.1531592979640; Sat, 14 Jul 2018 11:29:39 -0700 (PDT) MIME-Version: 1.0 References: <8916EC21-D368-40F8-9ABD-CE0C04A73539@gmail.com> <6E843F96-7815-4525-8AB1-D9D700B0D031@gmail.com> In-Reply-To: <6E843F96-7815-4525-8AB1-D9D700B0D031@gmail.com> Date: Sat, 14 Jul 2018 12:29:23 -0600 Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Non-nullable properties From: levim@php.net (Levi Morrison) On Sat, Jul 14, 2018 at 10:00 AM Rowan Collins wr= ote: > > On 14 July 2018 15:37:32 BST, Levi Morrison wrote: > >> class Validity { > >> public \DateTimeInterface $validFrom; > >> public ?\DateTimeInterface $validTo =3D null; > >> } > > > >Even if this had a constructor we couldn't "trust" it because there > >are ways to skip constructors. > > Then the mechanisms should either be impossible with non-nullable propert= ies, or have a way to mark the object initialised. If not, the object creat= ed would not be fully initialised, so accessing *the entire object* should = be an error, not just accessing the specific properties which are marked no= n-nullable. > > I'm not claiming any of this is easy, but if you can't guarantee a proper= ty has a valid value, what is the type hint actually for? Whether it's a constructor, a factory method, or just a block of code near the `new` site: something has the responsibility for initialization. Once initialized the object provides guarantees unless you `unset` the property. It also provides the guarantee that if it is set then it will always be of the outlined type; this is a much stronger guarantee than we have today, which is... nothing. It's worth discussing, and if someone has a brilliant idea maybe we can proceed. However, in the absence of such an idea am I fine with the outlined semantics of the RFC.