Maison > Article > développement back-end > php深入学习笔记2( 函数内置函数 )
php深入学习笔记二( 函数内置函数 )
function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2\n";}class foo { function bar($arg, $arg2) { echo __METHOD__, " got $arg and $arg2\n"; }}// 普通函数调用call_user_func_array("foobar", array("one", "two"));// 类成员函数调用$foo = new foo;call_user_func_array(array($foo, "bar"), array("three", "four"));
call_user_func(function($arg) { print "[$arg]\n"; }, 'test');
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');echo "New anonymous function: $newfunc\n";echo $newfunc(2, M_E) . "\n";
<?phpfunction sum() { $acc = 0; foreach (func_get_args() as $n) { $acc += $n; } return $acc;}echo sum(1, 2, 3, 4);?>
检测函数是否存在
function_?exists("函数名"); // 检测一个函数是否存在Array( [internal] => Array ( [0] => zend_version [1] => func_num_args [2] => func_get_arg [3] => func_get_args [4] => strlen [5] => strcmp [6] => strncmp ... [750] => bcscale [751] => bccomp ) [user] => Array ( [0] => myrow ))
function add(){ code here... } register_?shutdown_?function("add");