Home >Backend Development >PHP Tutorial >Detailed explanation of how to use variable functions in PHP
This article mainly introduces relevant information about the detailed examples of variable functions in PHP. I hope this article can help everyone understand and master variable functions. Friends in need can refer to it
Detailed explanation of examples of variable functions in 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() 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.
The above is the detailed content of Detailed explanation of how to use variable functions in PHP. For more information, please follow other related articles on the PHP Chinese website!