PHP calls the function via a string from: ziming.orgarchives6695.html? 1. call_user_funcfunctiona ($ B, $ c) {echo $ B; echo $ c;} call_user_func (a, 111,222); call_user_func (a, 333,444); PHP calls a function through a string
From: http://ziming.org/archives/6695.html
?
1. call_user_func
Function a ($ B, $ c) {echo $ B; echo $ c;} call_user_func ('A', "111", "222"); call_user_func ('A ', "333", "444 ");? // Display 111 222 333 444?>? // It is strange to call the internal methods of the class. actually, array is used, and developers do not know how to consider it. of course new is saved, which is also innovative: class a {function B ($ c) {echo $ c;} call_user_func (array ("a", "B"), "111 ");? // Display the 111?>
2. call_user_func_array
The call_user_func_array function is similar to call_user_func, but the parameter is passed in another way to make the parameter structure clearer:
Function a ($ B, $ c) {echo $ B; echo $ c;} call_user_func_array ('A', array ("111", "222 "));? // Display 111 222?>? // Can the call_user_func_array function call internal methods of the class? Class ClassA {function bc ($ B, $ c) {$ bc = $ B + $ c; echo $ bc;} call_user_func_array (array ('classa ', 'BC'), array ("111", "222 "));? // Display the 333?>
Call_user_func and call_user_func_array functions support reference, which makes them more functional than normal function calls:
Function a (& $ B) {$ B ++;} $ c = 0; call_user_func ('A', & $ c); echo $ c; // Display 1call_user_func_array ('A', array (& $ c); echo $ c; // Display 2