Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67244 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20014 invoked from network); 1 May 2013 12:35:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 May 2013 12:35:22 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.128.170 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.170 mail-ve0-f170.google.com Received: from [209.85.128.170] ([209.85.128.170:49868] helo=mail-ve0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/74-18873-80C01815 for ; Wed, 01 May 2013 08:35:20 -0400 Received: by mail-ve0-f170.google.com with SMTP id 15so1186272vea.15 for ; Wed, 01 May 2013 05:35:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=g+hnllrqqThGTK6K8/hDWpiQP9Lvq0ANTRf7/z5nZLU=; b=cQdDiPZQJ0uxcu8tXTPI0kRB+Dx6ZTXEtPzoXmHelYVoeK2ac2yHGRakP7uZeejcTR zbDKY/1JQYdxWGBQHhwbINkzaVqLH+RrDnyqs8dQM11i2nSgNajeJj5XBP5tub9BPCtb Cxozy+nWodbUCrpT6xHKmUuao13+AUCqyw233+73VnHHkgmDO3Br9M5aJemuLwLOlqIh F5IFabZsEUCzv46Bv24KXjFpcB2pjcLZrVOm0VesFfCGKcTK3D1vVAt/wUIj5Z5G0kv8 VptPDIJCk2joJfT7rR4sW8ii+rplm/Av8pP32fiwBqPljwdlYJMQdCPNrvt4w33Q6Nm4 3zXQ== MIME-Version: 1.0 X-Received: by 10.52.237.137 with SMTP id vc9mr666351vdc.102.1367411717769; Wed, 01 May 2013 05:35:17 -0700 (PDT) Received: by 10.58.28.134 with HTTP; Wed, 1 May 2013 05:35:17 -0700 (PDT) In-Reply-To: <5180652D.1080007@lerdorf.com> 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 08:35:17 -0400 Message-ID: To: Rasmus Lerdorf Cc: Stas Malyshev , PHP internals Content-Type: multipart/alternative; boundary=089e01176751b330a904dba7598b X-Gm-Message-State: ALoCoQnCjemiIRHITVzzKnWNo3MFROKED7JRTMuW/mrZrdhUzFzyIb3d0DO6W6cxYHxe1tpFxfh1 Subject: Re: [PHP-DEV] property de-referencing From: rasmus@mindplay.dk (Rasmus Schultz) --089e01176751b330a904dba7598b Content-Type: text/plain; charset=ISO-8859-1 > > 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; 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 > --089e01176751b330a904dba7598b--