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

Request #10502 Cache_Lite_Function::call should accept standard callbacks as 1st argument
Submitted: 2007-03-26 01:44 UTC
From: mrclay Assigned:
Status: Open Package: Cache_Lite (version CVS)
PHP Version: Irrelevant OS:
Roadmaps: 1.8    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 26 - 21 = ?

 
 [2007-03-26 01:44 UTC] mrclay (Steve Clay)
Description: ------------ A tiny patch (below) would allow Cache_Lite_Function::call() to accept all standard callbacks for the target function. Currently call() fails to handle static method callbacks because it assumes all arrays passed in are instance methods. This should allow this method to play better with others (may resolve bug 660) and might even slightly improve perf. (I ab-ed bench3.php (-c 10 -n 1000) and didn't really see a difference) Eventually requiring only standard callbacks would eliminate the entire if block. Test script: --------------- 129,132c129,130 < // in this case, $target is for example array($obj, 'method') < $object = $target[0]; < $method = $target[1]; < $result = call_user_func_array(array(&$object, $method), $arguments); --- > // callback pseudotype > $result = call_user_func_array($target, $arguments);

Comments

 [2007-03-27 02:03 UTC] demrit (Miguel Vazquez Gocobachi)
There is a good implementation, I don't think so it need be hacked. If you don't see any difference, why we need make changes then? For example, what happen if you have more than three parameters for $target? It will work? I think for this reason we have: $object = $target[0]; $method = $target[1]; So we know exactly what we are passing to the call_user_func_array().
 [2007-03-27 14:12 UTC] mrclay (Steve Clay)
@demrit: The change would allow Function::call() to accept the same arguments you would give to call_user_func(), namely the first one being a standard callback type: http://php.net/callback One trivial usage case: a function that takes a callback and some args. If caching isn't desired the function can just hand the callback directly to call_user_func() and return the result, if caching is desired, the function would require Cache/Lite.php, create $cache and give the callback to $cache->call(). This model would save the overhead of loading/instantiating Cache_Lite when caching isn't necessary/desired. Currently this would fail because call_user_func() doesn't understand the non-standard notation that call() expects. In short, the callback is the standard PHP "function pointer", so PEAR classes should accept it (and encourage its use). Cache_Function also reinvents the wheel in this manner: http://cvs.php.net/viewvc.cgi/pear/Cache/Function.php?annotate=1.8#l131
 [2014-05-10 14:48 UTC] tacker (Markus Tacker)
-Status: Assigned +Status: Open