php的可变函数,php之可变函数的实例详解
php之可變函數(shù)的實(shí)例詳解
php的可變函數(shù),今天大概的了解下,是看php手冊(cè)總結(jié)的,覺得用處不大;
PHP 支持可變函數(shù)的概念。這意味著如果一個(gè)變量名后有圓括號(hào),PHP 將尋找與變量的值同名的函數(shù),并且嘗試執(zhí)行它。可變函數(shù)可以用來實(shí)現(xiàn)包括回調(diào)函數(shù),函數(shù)表在內(nèi)的一些用途。
可變函數(shù)不能用于例如 echo,print,unset(),isset(),empty(),include,require 以及類似的語言結(jié)構(gòu)。需要使用自己的包裝函數(shù)來將這些結(jié)構(gòu)用作可變函數(shù)。
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()
class Foo
{
static $variable = 'static property';
static function Variable()
{
echo 'Method Variable called';
}
}
echo Foo::$variable; // This prints 'static property'. It does need a $variable in this scope.
$variable = "Variable";
Foo::$variable(); // This calls $foo->Variable() reading $variable in this scope.
如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
總結(jié)
以上是生活随笔為你收集整理的php的可变函数,php之可变函数的实例详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 筛选出一证多卡 用sql_对比Excel
- 下一篇: 水印鲁棒性的分析matlab程序,图像数