Re: Re: Function Cache
| From: | Sterling Hughes | Date: | Sun, 10 Dec 2000 17:27:14 +0000 |
| Subject: | Re: Re: Function Cache | ||
| References: | 1 2 3 | Groups: | php.dev php.pear |
| Request: | Send a blank email to php-dev+get-40750@lists.php.net to get a copy of this message | ||
> Stig S. Bakken wrote:
> > For objects, I think the best thing would be to create a function that
> > returns a proxy object. Then you can write code like this:
> >
> > $obj = new myclass(42);
> > $cached = new caching_proxy_object($obj);
>
> Hmm, is there a way to write a generic proxy class that can
> stand in for any class? I mean, if you call
>
> $cached->dosomething()
>
> how do you spare yourself to implement a dosomething() method in
> the proxy object? All methods in $cached would be implemented
> the same way: ob_start(), proxy call to $obj->dosomething(),
> then ob_get_contents() and ob_end_clear().
>
> Do we already have _delegate() methods in Zend? That is, is
> there already a way to specifiy a method that gets called before
> Zend complains that there is no dosomething() method in $cached
> and that can intercept the error message? If so, it is indeed
> possible to write generic proxy objects, otherwise you need to
> generate distinct code for each proxy class.
>
I've have some similair functionality (id est, Perl's AUTOLOAD) for my own
development. I was going to propose it when I had more time, but ah well,
AUTOLOAD.
Basically what this functionality would allow is that you define a function that
then catches as missed function calls. The autoload variable would also contain
the name of the missing function, ie:
class wrapper
{
function AUTOLOAD()
{
global $AUTOLOAD;
$args = func_get_args();
print "$AUTOLOAD was called with: ";
var_dump($args);
}
}
$wrap = new wrapper;
$wrap->hello("woohooo!");
would call the AUTOLOAD function with one argument (woohooo!) and the global
variable $AUTOLOAD would contain "hello".
-Sterling