Re: RFC: Property get/set syntax
| From: | Bernhard Schussek | Date: | Mon, 16 Jul 2012 21:26:48 +0000 |
| Subject: | Re: RFC: Property get/set syntax | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61324@lists.php.net to get a copy of this message | ||
Hi all,
Has array access been considered for properties? I can see a good use
for this for cross-referencing objects.
class Parent
{
private $_children = array();
public $children {
offsetSet { $value->parent = $this; $this->_children[$key] = $value; }
offsetUnset { $value->parent = null; unset($this->_children[$key]; }
// etc.
}
}
$parent = new Parent();
$child = new Child();
$parent->children[] = $child;
// $child->parent === $parent
Cheers,
Bernhard
2012/7/9 Clint Priest <cpriest@zerocue.com>:
> I've just recently had my second child and closed on a new house, so been a bit busy.
> I'll be working to finish up what's left in the coming weeks.
>
> Right now I'm told there are some conflicts with a merge from master that I have to
> resolve, then the fork will be ready for playing around with. Hopefully I'll have that fixed
> up later this week.
>
> From: Benjamin Eberlei [mailto:kontakt@beberlei.de]
> Sent: Thursday, June 28, 2012 4:55 AM
> To: Clint Priest
> Cc: Stas Malyshev; internals@lists.php.net
> Subject: Re: [PHP-DEV] RFC: Property get/set syntax
>
> What is the state here with regard to merge into php-src?
> On Sun, Apr 22, 2012 at 5:48 AM, Clint M Priest
> <cpriest@zerocue.com<mailto:cpriest@zerocue.com>> wrote:
>
>
>> -----Original Message-----
>> From: Stas Malyshev
>> [mailto:smalyshev@sugarcrm.com<mailto:smalyshev@sugarcrm.com>]
>> Sent: Saturday, April 21, 2012 10:33 PM
>> To: Clint M Priest
>> Cc:
>> internals@lists.php.net<mailto:internals@lists.php.net>
>> Subject: Re: [PHP-DEV] RFC: Property get/set syntax
>>
>> Hi!
>>
>> > empty() - Returns true for a property retrieved via __get() or via a
>> > getter -- Any idea why this would be the case for __get()? Is this a
>> > bug?
>>
>> isset() calls __isset(), empty() calls __isset() and __get(). I'm not sure what
>> exactly you consider to be a bug.
> I see, well the only way to resolve this would be to add isset and unset property functions as
> well.
>
> Anyone against it?
>
>>
>> > unset() - Would unset a temporary variable (the one returned by the
>> > getter) -- see previous email re: adding unset/isset property
>> > functions.
>>
>> unset() calls __unset().
>>
>> > sort() - Does the same thing as with __get()/__set() which is to say,
>> > the array is sorted but the property is not updated with the value.
>> > Should accessor behave differently than the magic methods? Should
>> > this just be documents or should this be fixed?
>>
>> sort() works just fine if you define __get to return by-ref.
> Returning by reference was not documented in the original RFC, would this syntax work for
> everyone?
>
> public $Hours {
> &get { return $this->a; }
> }
>
>>
>> --
>> Stanislav Malyshev, Software Architect
>> SugarCRM: http://www.sugarcrm.com/
>> (408)454-6900 ext. 227<tel:%28408%29454-6900%20ext.%20227>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>