RE: [PHP-DEV] [RFC] Propety Accessors v1.1

From: Date: Wed, 10 Oct 2012 12:02:30 +0000
Subject: RE: [PHP-DEV] [RFC] Propety Accessors v1.1
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-63320@lists.php.net to get a copy of this message
> > Second, I'd like to throw in the idea of array accessors. I mentioned > > this before, but did not get any response. > > > > public $Addresses { > > offsetSet($offset, $value) { ... } > > offsetGet() { ... } > > offsetUnset($offset) { ... } > > offsetExists($offset) { ... } > > } > > Definitely on the "nice to have" list. While I agree it would be a "nice to have" it would also be un-necessary. There are already ways to do precisely what is desired here by way of ArrayAccess. class Addresses implements ArrayAccess { offsetSet($offset, $value) { ... } offsetGet() { ... } offsetUnset($offset) { ... } offsetExists($offset) { ... } } // In base class where the proposed additional accessor types were suggested public $Addresses = new Addresses(); Or if you felt like using an accessor to control access to the Addresses object, you could implement that as well, but an accessor wouldn't even be necessary. This would provide for cleaner object-oriented principles, the logic for dealing with acceptance of a new address stays within a class designed to hold and control access to the collection of addresses.

« previous php.internals (#63320) next »