आप एक ही प्रभाव है क्या कर सकता है निम्नलिखित है:
<?php
class hooked{
public $value;
function __construct(){
$this->value = "your function";
}
// Only called when function does not exist.
function __call($name, $arguments){
$reroute = array(
"rerouted" => "hooked_function"
);
// Set the prefix to whatever you like available in function names.
$prefix = "_";
// Remove the prefix and check wether the function exists.
$function_name = substr($name, strlen($prefix));
if(method_exists($this, $function_name)){
// Handle prefix methods.
call_user_func_array(array($this, $function_name), $arguments);
}elseif(array_key_exists($name, $reroute)){
if(method_exists($this, $reroute[$name])){
call_user_func_array(array($this, $reroute[$name]), $arguments);
}else{
throw new Exception("Function <strong>{$reroute[$name]}</strong> does not exist.\n");
}
}else{
throw new Exception("Function <strong>$name</strong> does not exist.\n");
}
}
function hooked_function($one = "", $two = ""){
echo "{$this->value} $one $two";
}
}
$hooked = new hooked();
$hooked->_hooked_function("is", "hooked. ");
// Echo's: "your function is hooked."
$hooked->rerouted("is", "rerouted.");
// Echo's: "our function is rerouted."
?>
स्रोत
2009-12-27 01:49:18
यह। आपको फेकाडे पैटर्न का पालन करना होगा। एक रैपर वर्ग है जो उस ऑब्जेक्ट का "मालिक" है जिसे आप इन सभी कार्यों को ओवरराइड करना चाहते हैं। आवश्यकतानुसार विधियों को पारित करने के लिए __call() का उपयोग करें, उचित रूप से कोई अतिरिक्त कार्य करें। प्रदर्शन को पसीना न पड़े जब तक कि आपका कोड लगातार नहीं कहा जाता है और आपका ऐप सीपीयू-सीमित है (लगभग कभी भी मामला नहीं) - प्रोग्रामर का समय इस तरह के व्यापार-बंद पर निर्णय लेने पर प्रदर्शन से लगभग हमेशा महत्वपूर्ण होता है। –