Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91697 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10295 invoked from network); 16 Mar 2016 17:26:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2016 17:26:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.179 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.217.179 mail-lb0-f179.google.com Received: from [209.85.217.179] ([209.85.217.179:34007] helo=mail-lb0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/38-48430-C4799E65 for ; Wed, 16 Mar 2016 12:26:37 -0500 Received: by mail-lb0-f179.google.com with SMTP id k12so52501176lbb.1 for ; Wed, 16 Mar 2016 10:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=sq1ejh8g/Abvbgwy5Nad3ZclQ7WOwdvfQo4QhzQ0r5Y=; b=wDAGNCoztsGv+uvYkuFkjXE4VrFD2mWuU+MKam9HuNYef25urCieY3KKce7iF0cJka 4RcgdtJtcwZmaOdesH9F6soJ5o/LrogLTnx5RNfKHVBARX+J/UrcehUmy1iAWDQw67lq kd7d3wKaB7aOgwMt5PiRO/GHooosKFekN39wHYMAxpmnRXUwNI3Xw/WEoWlzA2lQZtFd 22i9pXcwIY9jFnf3yTGf8rPyvNszibIWBtBo2h95ZXlB45SNhBrycj5LklLDO9cCpp2m nvVYRAd0ngxozJDMc7n33ohEsXdIn/cdNesegm2hnPtb10y2shr3BGTJWHd6Q7FijeKn hElQ== 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=sq1ejh8g/Abvbgwy5Nad3ZclQ7WOwdvfQo4QhzQ0r5Y=; b=MMv7oH4ub5XnNKebjxQZXarOgBDE8yjqZ5No4n75/Wg8DJXW4d87UEk6Lt2ISmLMr6 NiXLxXOYpItJuxY4BgjMEn3U7MB0UIbf3Nco3gBsVVi3shqjcjb1uU1u1EKiVcYW9xa9 xa/DbQC5bf4mbEgk5JytzCGEL3+JhjRxw8t49g+YvTxSoAhuoSvVADED0gcj0kI5JTZG ObQz5v/5g9n9EmBnM2q1jxmcP1Q09zzTTm/U+sP1fhc4ZzMBtMmNzaDxfUhR3YMS0o2L j7qsVf7JYjh+amTlMYdtjmgI2N/ZZH7UTmd/0Mx/buYtvlnnzdJ/VQBqvTVKpQptUi+S biPA== X-Gm-Message-State: AD7BkJIMcDgAN//DXzUMLZ5inI/N2uif07dGdyJ2x2xNf3pK4CWu6OJJ+lFuCDLuVCyTz66KNjPlGg452RwO1Q== MIME-Version: 1.0 X-Received: by 10.112.141.132 with SMTP id ro4mr1932818lbb.104.1458149193975; Wed, 16 Mar 2016 10:26:33 -0700 (PDT) Received: by 10.114.78.71 with HTTP; Wed, 16 Mar 2016 10:26:33 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 Mar 2016 13:26:33 -0400 Message-ID: To: Adam Harvey Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: pjsturgeon@gmail.com (Phil Sturgeon) On Wed, Mar 16, 2016 at 1:08 PM, Adam Harvey wrote: > On 16 March 2016 at 09:36, Phil Sturgeon wrote: >> 3. Weak vs Strict. Right now this is entirely strict, with no >> declare() to change mode. Reasons for this vary, from various sources, >> but include "Not sure how to implement it" and "Well people should not >> be using properties as part of their public API". > > As much as I didn't (and don't) particularly like the declare() > switch, it doesn't seem like a good idea to me to introduce a typing > feature a year after it that doesn't use it, but has its own mode of > operation. To me, it seems like this: > > class Foo { > public int $num; > } > > (new Foo)->num = $bar; > > Should behave the same as the setter equivalent does today: > > class Foo { > public $num; > public function setNum(int $num) { $this->num = $num; } > } > > (new Foo)->setNum($num); > > That is: if $num either can't be coerced to an integer (in weak mode) > or isn't itself an integer (in strict mode), a TypeError should be > thrown. > > We could argue about whether properties should be part of a public > API, but the reality is that a class declaring a public property > effectively is making it part of its API, whether you or I think it's > a good idea or not. :) > >> We'll have a nice, orderly, constructive conversation about this RFC, >> and improve the patch as you all provide feedback. >> Let me know what you think folks! > > The above leads into another question I'm interested in your (and > Joe's) general thoughts on: how do you think this would potentially > intersect with a property getter/setter RFC in the future? Might be > good fodder for the future scope section! Yeah, I'll add a note about that. :) > Finally, while the RFC shows invalid assignments generating fatal > errors, the patch seems like it throws TypeError exceptions instead. > Which one is the desired behaviour? (I'd prefer TypeError, personally, > for consistency with function type declarations today.) > > Adam If you put them in the class definition you'll get a fatal error from the compiler (might change) and at runtime you get an Error. Different things for different things. :)