欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php之可變函數(shù)的實(shí)例詳解

 更新時(shí)間:2017年09月13日 08:36:52   作者:chenhaibo0806999  
這篇文章主要介紹了php之可變函數(shù)的實(shí)例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握可變函數(shù),需要的朋友可以參考下

php之可變函數(shù)的實(shí)例詳解

php的可變函數(shù),今天大概的了解下,是看php手冊總結(jié)的,覺得用處不大;

PHP 支持可變函數(shù)的概念。這意味著如果一個變量名后有圓括號,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ū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論