Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78440 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27333 invoked from network); 29 Oct 2014 04:29:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Oct 2014 04:29:27 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 209.85.212.178 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 209.85.212.178 mail-wi0-f178.google.com Received: from [209.85.212.178] ([209.85.212.178:61801] helo=mail-wi0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/F0-21571-62D60545 for ; Tue, 28 Oct 2014 23:29:27 -0500 Received: by mail-wi0-f178.google.com with SMTP id q5so3505311wiv.5 for ; Tue, 28 Oct 2014 21:29:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=weUXD3c7AlJvltpQDFpiWVI5iQRMIva42BlrCpelfwM=; b=S4U8F+f/cLqbGOoOrFviMcngZ069nSZno0ieIntQnctcaJA9/Wm1TBNVEvTx8t/sHs 0xlXn+6nY3NvhOA/8NE3TwQx6Sh7iuoxYpn4MxoTMDIT+Xf8e4XUFs63m0mXm1fU9SAb Yz1ijUvj1N6mGdnuEfEgIBNNN619XYj2pLA28FkJdAcLnddJjg34C3NgP1UpcPlLBie6 +xbFfnHKF7cNhlE2/3l/cllIfqpJVhKxtI4VbJ/aem7LqZRlOW79lcaw4GPLC04Iq2YY U9uwC43V594eSTwj4eiG3g9DENzPS98DS2c0wzZfLZ0ffd91Int6MQ0eL5W8AatAtORO b12Q== X-Gm-Message-State: ALoCoQnop5oMBnuZVW5NmrjC/cRhtjXm1TVjnMY8CQo7gN81WuTRvsVf82Qdg2T/TsqYvBOKvg3Y X-Received: by 10.194.142.147 with SMTP id rw19mr9723635wjb.64.1414556962624; Tue, 28 Oct 2014 21:29:22 -0700 (PDT) Received: from [172.20.21.94] (65-127-207-42.dia.static.qwest.net. [65.127.207.42]) by mx.google.com with ESMTPSA id mw7sm526582wib.14.2014.10.28.21.29.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Oct 2014 21:29:21 -0700 (PDT) Message-ID: <54506D20.3010402@seld.be> Date: Wed, 29 Oct 2014 04:29:20 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <6E04B9BE-854E-4112-8C74-7D90BD8BFE95@ajf.me> <544D48A3.6070905@gmail.com> <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> <544F4321.8040302@seld.be> <544FA716.2030508@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Readonly Properties From: j.boggiano@seld.be (Jordi Boggiano) On 28/10/2014 15:08, Andrea Faulds wrote: > >> On 28 Oct 2014, at 14:24, Rowan Collins wrote: >> >> Andrea Faulds wrote on 28/10/2014 14:08: >>>>> On 28 Oct 2014, at 07:17, Jordi Boggiano wrote: >>>>> >>>>> I like it, except for the fact that if you add a custom getter to a property suddenly it becomes readonly unless you remember to add "; set" to the end of the block, right? >>> Well, no. If you choose to specify getters and setters, and only specify a setter, of course it is read-only. It doesn’t make sense to have a getter and no setter and yet expect a property to be writeable. >>> >> >> I think the problem is that the get and set annotations are serving multiple purposes - to change the visibility, to define custom accessor/mutator code, but also to declare whether certain actions are possible at all. Since the default is for the property to be readable and writable, the fact that adding "{ get; }" makes it readonly isn't immediately intuitive, although it does makes sense once you think about it. > > Hmm. Perhaps we need this, then: > > public $foobar; // public read, private write > public/private $foobar; // public read, private write > public readonly $foobar; // public read, not writeable at all > > This then confined set/get entirely to implementation details. A read-only property would be denoted by readonly. > > With the last one, you can only have get, for the first two, you must have both get and set. > > Does that work? Seems pretty good to me. Yup that's definitely better than having the readonly flag in the {} block as I had it. I'd however say that it should be possible to define a writable property with only a getter and then the setter would implicitly be created. Since readonly is the way to define writability why should I have to specify a setter (even a default empty one) if none is needed? P.S: Don't want to open pandora's box, but we could also have writeonly for completeness perhaps. I don't really see the use case at all though (immutability sure, mutant bottomless pit objects not so much:). Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordi