Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.3

Bug #660 Problem using Cache_Lite_Function's 'call' method and $this->method
Submitted: 2004-02-01 11:45 UTC
From: eikke at eikke dot com Assigned:
Status: Wont fix Package: Cache_Lite
PHP Version: 4.3.3 OS: GNU/Linux 2.4
Roadmaps: (Not assigned)    
Subscription  


 [2004-02-01 11:45 UTC] eikke at eikke dot com
Description: ------------ If I try to use PEAR::Cache_Lite's Cache_Lite_Function class in a class of mine, I cannot cache results of methode calls of that class itself (error on $this->_cache->call('this->_myFunction', 'arg1', 'arg2')) These 2 possible solution do not work: a) $tmp=$this; $this->_cache->call('tmp->_myFunction', 'arg1', 'arg2'); b) $tmp=& $this; $this->_cache->call('tmp->_myFunction', 'arg1', 'arg2'); Reproduce code: --------------- <?php require_once 'Cache/Lite/Function.php'; class myClass{ var $_cache; function myClass(){ $options = array('caching' => true, 'cacheDir' => '../cache', 'lifeTime' => 1800); $this->_cache = new Cache_Lite_Function($options); } function _myTest($a, $b){ return $a."+".$b."=".($a+$b); } function getResult($c, $d){ $ret=$this->_cache->call('this->_myTest', $c, $d); return $ret; } } $mc=new myClass(); echo $mc->getResult(1,2); ?> Expected result: ---------------- 1+2=3 Actual result: -------------- Fatal error: Call to a member function on a non-object in /usr/local/lib/php/Cache/Lite/Function.php on line 103

Comments

 [2004-02-07 13:34 UTC] fab at php dot net
I don't find any good solution. But, a good workaround is : <?php (...) function getResult($c, $d){ global $temp; // WITHOUT THIS, IT DOESN'T WORK $temp = $this; $ret=$this->_cache->call('temp->_myTest', $c, $d); return $ret; } (...) ?>
 [2004-10-12 20:04 UTC] dcech at phpwerx dot net
You can call it like: $this->_cache->call(array(&$this,'myFunction'), 'arg1', 'arg2'); It will generate 2 notices but will work just fine.