<?php
function a(){}
$b = get_defined_functions();
print_r($b);
//也許會顯示1000多個已定義了的函數:)
?>
<?php
if (function_exists('a')) {
echo "yes";
} else {
echo "no";
}
function a(){}
// 顯示 yes
?>
<?php
function a($b,$c)
{
echo $b;
echo $c;
}
call_user_func('a', "111","222");
call_user_func('a', "333","444");
//顯示 111 222 333 444
?>
代碼:php
<?php class a { function b($c) { echo $c; } } call_user_func(array("a", "b"),"111"); //顯示 111 ?>
<?php function a($b, $c) { echo $b; echo $c; } call_user_func_array('a', array("111", "222")); //顯示 111 222 ?>
<?php function a(&$b) { $b++; } $c = 0; call_user_func('a', &$c); echo $c;//顯示 1 call_user_func_array('a', array(&$c)); echo $c;//顯示 2 ?>
代碼:數組
<?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; } foo(1, 2, 3); ?>
create_function函數能夠創建一個匿名的函數(函數名被PHP默認爲lambda_1,lambda_2),樣子比較古怪,可是形式比較奇特,要注意第二個參數內的語句要有「;」分隔:緩存
<?php
$newfunc = create_function('$a,$b', 'return $a + $b;');
echo $newfunc;
echo $newfunc(2, 3);
//顯示 lambda_1 5
?>
<?php function a() { echo 222 ; } echo 111; register_shutdown_function('a'); //顯示 111 222 ?> <?php class a { function b ($c) { echo $c; } } register_shutdown_function (array ('a', 'b'), '111'); //顯示 111 ?>
<? function foo($str) { static $i = 0; print "$str: $i<br>"; $i++; } register_tick_function("foo", "count"); declare (ticks = 6) { for($i=0; $i<20; $i++) { echo "$i<br>"; } } ?>