This article mainly introduces the PHP variable function example of the relevant information, hope that through this article can help everyone, so that we understand the variable function, the need for friends can refer to the next
An example of a variable function in PHP
PHP variable function, today about the understanding, is to see the PHP manual summary, feel less useful;
PHP supports the concept of mutable functions. This means that if a variable name has parentheses after it, PHP will look for a function with the same name as the value of the variable and try to execute it. Variable functions can be used to implement some purposes, including callback functions, function tables, and so on.
Mutable functions cannot be used for example Echo,print,unset (), Isset (), Empty (), Include,require, and similar language constructs. These structures need to be used as mutable functions using their own wrapper functions.
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 the This scope.