Home>Article>Backend Development> What is the way to call a class with string name in PHP
PHP uses the string name to call the class method: 1. Use the [call_user_func] method, the code is [call_user_func(array($game, 'Play'), 1)]; 2. Use the Play method, the code It is [$game->{'Play'}(2)].
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer. This method is suitable for all brands of computers.
PHP uses the string name to call the method of the class:
You can use thecall_user_func
method and the Play method
The specific code is shown below:
{'Play'}(2); //或者 $method = 'Play'; $game->$method(3);
Related video recommendations:PHP programming from entry to proficiency
The above is the detailed content of What is the way to call a class with string name in PHP. For more information, please follow other related articles on the PHP Chinese website!