Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91765 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2509 invoked from network); 19 Mar 2016 09:51:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2016 09:51:11 -0000 Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.161.170 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.161.170 mail-yw0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:34678] helo=mail-yw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/44-03097-D012DE65 for ; Sat, 19 Mar 2016 04:51:09 -0500 Received: by mail-yw0-f170.google.com with SMTP id h129so166663799ywb.1 for ; Sat, 19 Mar 2016 02:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pthreads-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=B1B2IMSxZ7kTBdTg+XnrjfiEr+AYovEIz8+NAyJwp8w=; b=i3BrfusKeukDrkb/ta6Fxk06NBXfm8D30AAcGRPmvO3z3mnTTol+XbDHhDZiyfLsJ9 GlS8WPvLrEmfOuy3E7ySy/Ur1eCOtnuj55dUFM4nF1H0XJNIEw8Smm/611aV5Qo/sXyj NiLtCFhDKDFJ/XGyBLaSN0fprYCakaBTGHwB9XgvVqIK51IDAPNnPIUhaSpaQ6ene85y CGeaWY9qppLOfuwy0+cAwLN89QGbfuCNBh8oOMoms7sPK/xLyoulT1TMJ+gVGnGFYkXw ZBFwZsNRfdmpknXgq6f/w8vXNPwp/obLxkbHtVGshg1V0AfcJilkMHjC5FhsLJnAQAVC 1vyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=B1B2IMSxZ7kTBdTg+XnrjfiEr+AYovEIz8+NAyJwp8w=; b=JvVTMt5CR3+e32dYjD+nygLlTweF1yjo4dM8nl3OVr616J2rZaeLVpAI2W3lw85lpf 0jBSP2AC0lyPVxLEyvBmVA/vtnKB1cYra/+9ObEc6kwrlrc+xAQfaMMhxkRS2Qe45QBM 7neLq2jylJ0xCpUORti712rFENE+AMP4viI1PunXlfRruBmPLn/XDlQfLFXXiB+jTszy GohJcJvtuTAat0gJL5Pdre773LNXK5Sp6FMlJOrtp7kTP9P71/01IVNB9GejyuuIQYR8 NHG33m61bKRVfO/PW9TOu21g2t+2m8Zbn9ZQ3Tn5T4lZsF640FEu0WjI4xE9ffIPZaI9 JqWw== X-Gm-Message-State: AD7BkJIXJj5f3vNvX0COtzKDeBpNgkY1F3n6Y7N9g5D4lUBQbiAZ9G4dv1Z/JVaT3bkpJhQ95p5Q/ct6QgDvPw== MIME-Version: 1.0 X-Received: by 10.129.91.132 with SMTP id p126mr9084045ywb.188.1458381066204; Sat, 19 Mar 2016 02:51:06 -0700 (PDT) Received: by 10.13.233.193 with HTTP; Sat, 19 Mar 2016 02:51:06 -0700 (PDT) X-Originating-IP: [86.191.46.104] In-Reply-To: References: Date: Sat, 19 Mar 2016 09:51:06 +0000 Message-ID: To: Lee Davis Cc: Phil Sturgeon , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114c7862662750052e63cd5f Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: pthreads@pthreads.org (Joe Watkins) --001a114c7862662750052e63cd5f Content-Type: text/plain; charset=UTF-8 Morning Lee, > Makes sense. AccessTypeError, WriteTypeError to both extend TypeError? Well maybe ... I'm not sure there is much purpose in distinguishing between the two, while the engine doesn't make the distinction for normal untyped properties. If we make the distinction for typed properties, why do untyped ones behave differently ? We have to make every effort for typed and untyped properties to be consistent with each other, even if strange ... > I'd still prefer the TypeError to only occur on setting rather than on access as well This would provide the opportunity for you to violate the declared type: $foo = new class { public int $bar = 10; public function __construct() { unset($this->bar); } public function __get($name) { return "oh dear!"; } }; var_dump($foo->bar); In order to provide those "perfect" guarantees we must not allow that to happen. Zend objects aren't just full of the magic you know about in user land, they can work in all kinds of strange and wonderful ways: Bottom line, the value you wrote doesn't have to be the one returned when you read, for all kinds of reasons. The fact is the check is extremely cheap and without them, declaring the type of the property in the first place would be pointless. Cheers Joe On Sat, Mar 19, 2016 at 9:17 AM, Lee Davis wrote: > Hi Joe, > > >> Accessing the property before it was unset though, as it always did, >> attempts to read the default value (null). >> >> We haven't changed any of that ... >> > > > Yes, you're right, this is exactly how it currently behaves : > https://3v4l.org/YpfYe (apologies for not checking this first). > Still seems inconsistent, but that's now outside the scope of the RFC. > > >> The most you can say about this, is that it's strange that the same >> exception is raised for both cases, which we're aware of; Right now, it's >> impossible to distinguish between the two states. >> > > Makes sense. AccessTypeError, WriteTypeError to both extend TypeError? > > >> >> The things you can be sure of: >> >> - If you get a value from an access of a typed property, it is the >> correct type. >> - If you get exceptions, you have logical errors in your code. >> > > Perfect. I'd still prefer the TypeError to only occur on setting rather > than on access as well (along with a fair amount of others: > https://twitter.com/leedavis81/status/710872866556874753), this would > then have the RFC only concerned itself with the WHAT rather than the WHEN, > but as long as that promise can be upheld then it's a great feature to have. > > I think adding in rules at the language level to dictate when it should be > set (i.e after construct) is a bad move, so I'd be in favour of leaving it > as it stands at the moment. Property accessors could solve the problem of > uninitialised properties later on. > > Cheers for all your hard work guys, > > Lee > /@leedavis81 > --001a114c7862662750052e63cd5f--