PHP Call Function Example via string

Source: Internet
Author: User

  This article mainly introduces PHP through the string call function, need friends can refer to the following

1. Call_user_func     Code is as follows: function A ($b, $c) {  echo $b;   echo $c;} call_user_func (' A ', "111", "222" ); Call_user_func (' A ', "333", "444");  //Show 222 333 444?>     Calling class internal method is strange, incredibly with array, do not know how to consider the developer, of course, save the new, but also full of innovative:   Code as follows: Class A {  function B ($c) {    echo $c;  }} call_user_func (Array ("A", "B"), "111");  /Show?>     2. The Call_user_func_array   Call_user_func_array functions are very similar to Call_user_func, except that they are passed in a way that gives the parameters a clearer structure:     code as follows: function A ($b, $c) {  echo $b   echo $c;} call_user_func_array (' A ', Array ("111", "222"));  //Show the 222?>     Call_user_func_array function can also invoke the   code of the method inside the class as follows: Class classa{  function BC ($ B, $c) {      $BC = $b + $c;     echo $bc;  } call_user_func_array (Array (' ClassA ', ' BC ') Array ("111", "222"));  //Show 333?>     CALL_USER_FUNC functions and Call_user_func_array functions support references, which makes them and ordinary function calls more reactiveCan be consistent:     code as follows: Function A (& $b) {  $b + +;} $c = 0; Call_user_func (' A ', & $c); echo $c//Display 1 Call_user_func_array (' A ', Array (& $c)); echo $c//Show 2  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.