Re: Use "caller" keyword, to access object caller.
Am 01.02.2015 01:15 schrieb "S.A.N" <[email protected]>:
>
> $holder->object->call($holder);
The way I solve this in the very few places (*) where it makes sense, is to
use __call in the holder class to implement forwarding methods that pass on
the holder object reference. The member property is NOT exposed.
Call will be like this: $holder->object_call();
Code could look something like this (untested):
class holder {
public function __call($method, $args) {
list ($propname, $membermethod) = explode('_', $method, 2);
if (!property_exists($this->$propname) || !is_object($this->$propname))
// add other policy
return null; // or any other error behaviour
return $this->$propname->$membermethod($this, ...$args);
}
}
(*) really just one place at the moment, tightly coupled, and not as
general as shown above. I don't see a use for the fully general case, where
the member objects would both care about knowing their holder object _and_
work with practically any holder object.
best regards
Patrick
Thread (19 messages)