Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5336 invoked from network); 16 Mar 2016 17:09:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2016 17:09:18 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.215.50 mail-lf0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:34935] helo=mail-lf0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/27-48430-C3399E65 for ; Wed, 16 Mar 2016 12:09:18 -0500 Received: by mail-lf0-f50.google.com with SMTP id l202so24216365lfl.2 for ; Wed, 16 Mar 2016 10:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=qnRAsZgPz6OZuphnOZ9U1ooVy41kB8u3mg6FiekG4vk=; b=NMo69paSuBHJaioNb+gNLuhX0/QbQV8bc0h9etxgE8UinmmCVCsDc7LNDCjYwPgukm KGbGq+4TXtBGa+1gjLqXvTJM8kZSeoMQRV0pRoapkktrVx5ThWk/zau1Aye9VZRCVH0X srrDG9eTeHzKJse37Y1f2JBsAmB3C76lzUla0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=qnRAsZgPz6OZuphnOZ9U1ooVy41kB8u3mg6FiekG4vk=; b=eQYCPo44JoxEjpTmPh7AByzSZ0EMQbYUpWu9O9X8lCcdtiCAwXv52MXFPy3V/DlRdh 2kX1lPI01k9tjzvpLcVPFYRm7oArWqBRtOTlDwNjZO/UpfoD5POuKRBb1qDnDyZ0UaDV BYrGs/50BeJWGzbH1OAFxr7zvt4cAQaKD7aMFI15J8xsovrCX/xaeCAEQBOES3fBgra8 PKA8uu12pgituQIaH03XoFRWdupKfFkTFSsfjYl2AELVr1pyY9XuP0baoriOSFzGHXdb DOTwSzQLh6fC1e5cVm42vLcCuJAzJ3PskyvmSoDv76EsLLseB/aogYWBdsOdG3kquji+ jdpw== X-Gm-Message-State: AD7BkJJnAHmo+WS7ZU3YuwS9uRbb0E8nuMXpow4Rfy+rlja2ln9JSb+S7canYt3cz2IE0EGggqgv4iuneUt4OA== X-Received: by 10.25.146.145 with SMTP id u139mr1959722lfd.113.1458148153765; Wed, 16 Mar 2016 10:09:13 -0700 (PDT) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.25.207.78 with HTTP; Wed, 16 Mar 2016 10:08:53 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 Mar 2016 10:08:53 -0700 X-Google-Sender-Auth: 6zAUEgox66PrG1dBb0XE4sv8wfs Message-ID: To: Phil Sturgeon Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: aharvey@php.net (Adam Harvey) 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! 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