復制代碼 代碼如下:
<?php
function foo () {
echo "In foo()<br />/n" ;
}
function bar ( $arg = '' ) {
echo "In bar(); argument was ' $arg '.<br />/n" ;
}
// 使用 echo 的包裝函數
function echoit ( $string )
{
echo $string ;
}
$func = 'foo' ;
$func ();// This calls foo()
$func = 'bar' ;
$func ( 'test' ); // This calls bar()
$func = 'echoit' ;
$func ( 'test' ); // This calls echoit()
?>
還可以利用可變函數的特性來調用一個對象的方法。
復制代碼 代碼如下:
<?php
class Foo
{
function Variable ()
{
$name = 'Bar' ;
$this -> $name (); // This calls the Bar() method
}
function Bar ()
{
echo "This is Bar" ;
}
}
$foo = new Foo ();
$funcname = "Variable" ;
$foo -> $funcname (); // This calls $foo->Variable()
?>
新聞熱點
疑難解答