Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97445 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59806 invoked from network); 19 Dec 2016 22:47:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Dec 2016 22:47:30 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:34462] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/63-36089-D7368585 for ; Mon, 19 Dec 2016 17:47:27 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 5F35820716 for ; Mon, 19 Dec 2016 17:47:23 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Mon, 19 Dec 2016 17:47:23 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=HSE+sONz2p5cNx/5TEzwaGTIhpc=; b=JXt6N3s/EiVN4F8lckOe 9FPxMyjE4MyD2MGjW9UeYW/C2LKD0b2ZpNpyx6BHVYgKshZkR50znZQF+e2uW7Ga QAk0nfILEuekcW1hhzW3MYnP7RQ4s1h/JEr1w4P8TycFvKBXdAs4rIOnSxKz3C3U fYyYo44zdzH/Cqjygc9R+64= X-ME-Sender: X-Sasl-enc: Q5Fblrcq0s7tYdii/K5kGuIrjILd3KfqU0JwFjnAls67 1482187643 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 176007E7C5 for ; Mon, 19 Dec 2016 17:47:23 -0500 (EST) To: internals@lists.php.net References: <6d4632cb-93b3-4237-a803-6b7ec13dae4a@Spark> Message-ID: Date: Mon, 19 Dec 2016 16:47:21 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <6d4632cb-93b3-4237-a803-6b7ec13dae4a@Spark> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Revisit_RFC_=e2=80=9cProperty_Accessors_Syn?= =?UTF-8?Q?tax_1.2=e2=80=9d?= From: larry@garfieldtech.com (Larry Garfield) On 12/19/2016 02:57 PM, ilija.tovilo@me.com wrote: > Hi everyone > > There was an RFC about a C#-like property syntax almost four years ago that got declined: > https://wiki.php.net/rfc/propertygetsetsyntax-v1.2 > > It failed by only 2-3 votes. In my opinion, PHP is still in need of this feature as it would make the language much more expressive. Let me start by defining the problem. First of all, almost all PHP frameworks hide their variables behind getters and setters. Here are some of the reasons why that is a good idea, I’m sure there are many more: > > - Ability to sanitize input > - Ability to lazily load data when requested (getter was called) > - Ability to expose only getter or setter publicly > - Easily mockable accessors for unit tests > - Ability to execute arbitrary code when accessors are called > - Modifiable business logic without breaking the API > > Here are some of the negatives, though there are probably more here as well: > > - Large boilerplate for normal getters/setters > - Inconsistent syntax for reading/writing data > - Calling a method for setting data instead of using the more intuitive `=` operator > - Calling a method for accessing foreign variables while accessing private variables directly > - Inability to use built in assignment operators like .=, +=, -=, etc. > - Disregard of the DRY principle > > The positives clearly outweigh the negatives as they are mostly syntactical. This is probably why using getters/setters everywhere has been a good-enough solution for such a long time. Because of that, just like the positives, the negatives have become a part of the language. Clearly, abandoning getters and setters is no option for anyone. Nonetheless, the RFC I linked above offers a way to get rid of the negatives without sacrificing any of the positives. > > Are there still any people who would like to see this happening just as much as I do? > I’m wondering if some of the people who have voted against the RFC might have changed their opinion or vice versa. > > Many thanks for reading! > > Regards, > Ilija As I understand it from those involved, most people did want that feature. I still do. :-) However, there is as of yet no confirmed way to add it without more of a performance hit than many folks are willing to accept. That is, it's not the concept people object to, just the implementation. If someone can figure out how to make that work with a small enough performance hit (where 0 would be ideal, but I don't know if that's even possible), that person would make a lot of devs (including me) very very happy. I am, sadly, not such a person. --Larry Garfield