How does php implement dynamic parameter transfer?

Source: Internet
Author: User
How does php implement dynamic parameter transfer ??? At last, this post was edited by ic2y _ in 2014-04-1717: 21: 01 and the code was simplified. & Lt ;? Php & nbsp; class & nbsp; Cache {public & nbsp; function & nbsp; get () {$ invoker & nbsp; how does deb php implement dynamic parameter transfer ???

This post was last edited by ic2y _ at 17:21:01

Paste the code first, and the code is simplified.


class Cache{
public function get()
{
$invoker= debug_backtrace();
$invoker_class= $invoker[1]["class"];
$invoker_function= $invoker[1]["function"]."_redirect";

$argus= func_get_args();
$invoker_class= str_replace("Action","", $invoker_class);

D($invoker_class)->$invoker_function($argus);
}
}
?>

Description:
The program is developed in ThinkPHP to forward the parameters received by the Cache get method to the specified method,
Last line: The D method is the singleton mode that comes with ThinkPHP. If the $ argus parameter is not added, it can be called normally.

Problem:
Now you want to pass parameters, such as get ("name", "age"), to D ($ invoker_class)-> $ invoker_function ("name", "age ").

Call_user_func seems to be okay, but it cannot be seen how to use it.

.
------ Solution --------------------
Call_user_func_array (array (D ($ invoker_class), $ invoker_function), $ argus );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.