Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67251 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34760 invoked from network); 1 May 2013 14:38:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 May 2013 14:38:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.175 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.82.175 mail-we0-f175.google.com Received: from [74.125.82.175] ([74.125.82.175:37322] helo=mail-we0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/D0-28617-AF821815 for ; Wed, 01 May 2013 10:38:51 -0400 Received: by mail-we0-f175.google.com with SMTP id i48so1288214wef.20 for ; Wed, 01 May 2013 07:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=5cUHct5sB8aYnvvNI35YHJ4yJvjb2Dv01DvRFIsmqhM=; b=owMIUWfk96/Nwg341hyP6Rz25ueoRJbD/3Pkgz2iFMSwWMinB8NEvgPWSWIBSbaYmY mmANcJL0+6WOH3km1PSAxE1zEsXxGOnf5CFWsk9msr+1RUPSKL/YnBtFIRsZR+RPZ0Kw hfPGQf+KfMuhdwfUOwioV70XVLvpW5+3EuEyBJGtLPr5WmHh2W9/xOeIezsnNIjBYAGp IwdBmRUkzykA3Xdq8PnA3pgnGFmD7jLyKz2e2MfdNt2tNW1/Ij3nwCYXDNh0ITnCc7aZ cX0TSf0jRzLk+QV/kYlHDQlk+2Cnt8oU5/zbTk8rSmbLSFJml6v5vBTcVLBlH80H0iuU 9ZFw== MIME-Version: 1.0 X-Received: by 10.180.182.135 with SMTP id ee7mr3103234wic.21.1367419126706; Wed, 01 May 2013 07:38:46 -0700 (PDT) Received: by 10.227.214.135 with HTTP; Wed, 1 May 2013 07:38:46 -0700 (PDT) Received: by 10.227.214.135 with HTTP; Wed, 1 May 2013 07:38:46 -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 10:38:46 -0400 Message-ID: To: Rasmus Schultz Cc: Rasmus Lerdorf , PHP Internals , Stas Malyshev Content-Type: multipart/alternative; boundary=089e01634fda4e774f04dba913d5 Subject: Re: [PHP-DEV] property de-referencing From: theanomaly.is@gmail.com (Sherif Ramadan) --089e01634fda4e774f04dba913d5 Content-Type: text/plain; charset=ISO-8859-1 On May 1, 2013 8:35 AM, "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 This is like building something and then going out to find a problem that it will hopefully solve. > to convince anyone they need anything they don't understand - I think the Perhaps the reason you're having trouble convincing anyone that they need it is simply because they don't need it? Things I need that solve real world problems for me are pretty obvious to me. I'm sure the solution wasn't always obvious but the problem definitely was. > 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; > > 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 > > --089e01634fda4e774f04dba913d5--