Re: [RFC] Propety Accessors v1.1
| From: | Bernhard Schussek | Date: | Wed, 10 Oct 2012 12:33:24 +0000 |
| Subject: | Re: [RFC] Propety Accessors v1.1 | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63321@lists.php.net to get a copy of this message | ||
2012/10/10 Clint Priest <cpriest@zerocue.com>:
> 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) { ... }
> }
This approach does not work for the use case I presented:
class Addresses implements ArrayAccess {
public function offsetSet($offset, $address) {
$this->_Addresses[] = $address;
$address->Contact = $contact; // where do we get the contact from?
}
}
If we pass $contact to the Addresses instance, the class is bound to
Contact and cannot be used anymore for different associations that
* do not involve Contact
* have a different arity (one-to-many: $address->Contact = $contact,
many-to-many: $address->Contacts[] = $contact)
Consequently, we would need to create a new collection class for each
to-many association, which is neither pragmatic nor good OO design.