2012/10/10 Clint Priest <[email protected]>:
> 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.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php