Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93579 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81562 invoked from network); 26 May 2016 17:22:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 17:22:09 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:38516] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 86/4C-17600-0C037475 for ; Thu, 26 May 2016 13:22:09 -0400 Received: by mail-wm0-f53.google.com with SMTP id n129so108246488wmn.1 for ; Thu, 26 May 2016 10:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=HpjsrCsl7oJPr01GpQiJ2/997RHsai8eiAIAhNK2ARg=; b=i6O1wgTObiuwPMpghlocSDArXJ/ubGEoIYX+uGqHndrjq76fDTyzP6XT9HfruRJa5T i0XT7LDpoIHZYk1MgcgBmuviQ12+OnZ/HocwZ26Oku3Kk7iykxNOEXLo+zjc3gM6r1Oi ipT5aBtnhQNADdWfyCOe6NJhBGHMScdtA4iwZv2d1kFmhR6fFQiUREz7Hx53A2Louy1V cS5Inbnd2jqhnfAeb8rlaGVprRw6IVs9jAm+OWy1KSE54de3VJj790tWwiJOnX4phUiJ DFkEuaYjolevGLzolU+W42Ra6NDc2+x6QwzKEODB1phkY5GYObI+FMZlO8FI8EtPb8jK z+0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=HpjsrCsl7oJPr01GpQiJ2/997RHsai8eiAIAhNK2ARg=; b=NWC+fudQmCVh9ykhQQz9bdlKI9tIhmcs+g2AWot3lCOyvfrJWxTcnWycVYoHl7aQc9 8VhUUG4uz3fzUEJobc8NLm5j44shcGwKVQnDxOVd0oBf53+/IiGaUaCYIeQRONlE93J4 quJBqV6vSG/itp+64s67lKicF9zs1SxqbqVxBTOokstJqBz1chAaBMcat094YMbtfrHI 5qhufqruv3Z3wMkPBGwOSLthaF6TVohSJkjMvjvRhggPRvGWKRuobZx68QtWxnacO1Vg NMh6NzhiMv8HAQvRT5TrVmk5Pxl2/JbnHTZES+nT+KepnlyDYF6pA4e+yXHudYxmZdtd CMHQ== X-Gm-Message-State: ALyK8tIq0EO8JgbaN36zDkxrxCogHDhYxQZ6MOlXpIiz4lB6kUn3ZrYauLXeoF+wWDQrjw== X-Received: by 10.194.105.4 with SMTP id gi4mr11002110wjb.87.1464283325361; Thu, 26 May 2016 10:22:05 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id a81sm4515129wma.16.2016.05.26.10.22.04 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2016 10:22:04 -0700 (PDT) To: internals@lists.php.net, Stanislav Malyshev References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> <08963b03-8394-6d62-4e5b-393f3fcb5647@fleshgrinder.com> Message-ID: <9e9db70d-d72d-d93e-0c81-18c2aa228618@gmail.com> Date: Thu, 26 May 2016 18:20:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <08963b03-8394-6d62-4e5b-393f3fcb5647@fleshgrinder.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: rowan.collins@gmail.com (Rowan Collins) On 26/05/2016 17:57, Fleshgrinder wrote: > On 5/26/2016 6:50 PM, Rowan Collins wrote: >> As I'm sure has already been pointed out (I haven't followed the whole >> thread) this defeats a large advantage of typed properties - I now can't >> read from the property without checking if it's null, so I can't do this: >> >> class O { >> public \DateTimeImmutable $d; >> } >> echo (new O)->d->format('Y-m-d H:i:s'); >> >> There's no ? on the type def, so I ought to be able to trust the type. A >> TypeError makes more sense here, because it is a programming error for >> it to be in this state. >> > > That is exactly what Stanislav raised too. I really have no idea how we > should prevent this from happening and honestly think we shouldn't. Your > construct will result in a fatal error (also known as > NullPointerException to some, *evil-laughter*) anyways preceded by an > E_NOTICE that tells you that your property is not defined. > > I am of course open for ideas but emitting another kind of fatal error > does not really make things better imho. I think the difference is the emphasis of whose responsibility it is to fix it: a TypeError confirms that the error is in the O class for exposing an incorrectly typed property; a NullPointerException, as you put it, makes it my fault for trusting the class. Or to put it a different way, is the error in the first arrow (accessing "->d") or the second one (de-referencing "d->"). At the end of the day, all the type notations being added to PHP are just assertions anyway. So the same could be said of this: function foo(\DateTime $d) { echo $d->format('Y-m-d H:i:s'); } foo(null); If this didn't throw an error at "foo(null)", it would throw an error at "$d->format". Regards, -- Rowan Collins [IMSoP]