Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32777 invoked from network); 1 May 2013 14:24:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 May 2013 14:24:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.48 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.216.48 mail-qa0-f48.google.com Received: from [209.85.216.48] ([209.85.216.48:46091] helo=mail-qa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/70-28617-7B521815 for ; Wed, 01 May 2013 10:24:55 -0400 Received: by mail-qa0-f48.google.com with SMTP id bn16so809360qab.0 for ; Wed, 01 May 2013 07:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=lV+4eo7WGW4A/7EuMn7bMm1azEuTPdFl9itDEATPjwQ=; b=W8ilnoP5Xfe9hi/T55PrQuHvnMTbb5/jlbtqB/LVxSUTfWHuXwhrsQJNT6gKL3mIxF 9cau5KCnrHsGiD7XIDN1gImLMsTmhhBfcD0RVq/6xgvaexsdHm+IeZy0Va1cGWJk5jrW o063UTMG5lPXm1RTkGBL5GBFjG795wy0k7ctycTOiCLzKuhT9NMINOWSRKcQCdHwljz+ +zfIjrjQBJp6iPDWPlEFR4Sr7Epi5dJ0fwR/IRo+ANHD1Rv+ZS3K8gd8Yir0CH19TP2A 2rU7IvKWJti6e23CKBU92jfsIsWU9CgVP5oJUcBOkaAyM8r5mtq/4igAq9CH98YnCN/j 1BLg== X-Received: by 10.49.95.163 with SMTP id dl3mr3313217qeb.38.1367418292696; Wed, 01 May 2013 07:24:52 -0700 (PDT) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.49.87.70 with HTTP; Wed, 1 May 2013 07:24:32 -0700 (PDT) In-Reply-To: References: <6245ED6B-2BF7-47B7-80C0-D3B3D8E0B312@strojny.net> <51803086.6020002@sugarcrm.com> <51805A00.4050803@lerdorf.com> <5180652D.1080007@lerdorf.com> Date: Wed, 1 May 2013 16:24:32 +0200 X-Google-Sender-Auth: fh0__HOA1YvZVvxKpIumPHUuHVM Message-ID: To: Rasmus Schultz Cc: Rasmus Lerdorf , Stas Malyshev , PHP internals Content-Type: multipart/alternative; boundary=047d7b6787ce987ea404dba8e112 Subject: Re: [PHP-DEV] property de-referencing From: colder@php.net (Etienne Kneuss) --047d7b6787ce987ea404dba8e112 Content-Type: text/plain; charset=UTF-8 On Wed, May 1, 2013 at 2:35 PM, Rasmus Schultz wrote: > > > > This is a fringe feature, as evidenced by the fact that you > > are having a hard time convincing people that it is needed > > > As with anything that isn't already established and well-known, it's hard > to convince anyone they need anything they don't understand - I think the > barrier here is me having difficulty explaining a new idea/concept. That > doesn't make it a fringe feature - I have already demonstrated by example > how this would be useful in practically every mainstream framework. > > Properties simply don't carry > > this information with them so a lot of things would have to change > > internally for this to ever work > > > I'm not sure what information you're referring to? > > Let's say for the sake of argument, I'm going to use a pre-processor to > transform the following code: > > $prop = ^$user->name; > > var_dump($nameprop->getValue()); // => 'Rasmus' > > $nameprop->setValue('Bob'); > > var_dump($nameprop->getValue()); // => 'Bob' > > The pre-processor output might look like this: > > $nameprop = new PropertyReference($user, 'name'); // $prop = ^$user->name; > So basically you want to introduce syntactic sugar for: new PropertyReference($user, 'name') The only reason being that the syntax "^$user->name" is "more static" than new PropertyReference($user, 'name'), and thus easier to refactor? To me they really look equivalent from a refactoring point of view. In any case, as many already pointed out, this sounds like a lot of pain for really little (if any) gain. > > var_dump($nameprop->getValue()); // => 'Rasmus' > > $nameprop->setValue('Bob'); > > var_dump($nameprop->getValue()); // => 'Bob' > > Only the first line changes - the rest behaves and runs like any normal PHP > code. > > And the PropertyReference class could be implemented in plain PHP like > this: > > class PropertyReference > { > private $_object; > > private $_propertyName; > > public function __construct($object, $propertyName) > { > $this->_object = $object; > $this->_propertyName = $propertyName; > } > > public function getObject() > { > return $this->_object; > } > > public function getPropertyName() > { > return $this->_propertyName; > } > > public function getValue() > { > return $this->_object->{$this->_propertyName}; > } > > public function setValue($value) > { > $this->_object->{$this->_propertyName} = $value; > } > > // and maybe: > > public function getReflection() > { > return new ReflectionObject($this->_object); > } > } > > > You can see the above example running in a sandbox here: > > > http://sandbox.onlinephpfunctions.com/code/87c57301e0f6babb51026192bd3db84ddaf84c83 > > Someone said they didn't think this would work for accessors, so I'm > including a running sample with a User model that uses accessors: > > > http://sandbox.onlinephpfunctions.com/code/f2922b3a5dc0e12bf1e6fcacd8e73ff80717f3cb > > Note that the dynamic User::$name property in this example is properly > documented and will reflect in an IDE. > > > On Tue, Apr 30, 2013 at 8:43 PM, Rasmus Lerdorf > wrote: > > > On 04/30/2013 05:17 PM, Rasmus Schultz wrote: > > > > > If the asterisk (or some other character) offers and easier > > > implementation path, whatever. > > > > It doesn't. This is a fringe feature, as evidenced by the fact that you > > are having a hard time convincing people that it is needed, and thus > > shouldn't overload an existing operator. Visually it would be confusing > > to take any well-known operator and give it a different obscure meaning. > > But yes, syntax-wise ^ could be made to work, the implementation problem > > I referred to is lower-level than that. Properties simply don't carry > > this information with them so a lot of things would have to change > > internally for this to ever work and if a clean implementation could be > > found, like I said, adding it to the reflection functions is the proper > > place. > > > > -Rasmus > > > -- Etienne Kneuss http://www.colder.ch --047d7b6787ce987ea404dba8e112--