Home > Article > Backend Development > PHP uses the name of a string to call a class development idea sharing
In the previous articleSample analysis of php dynamically generating objects based on string class namesWe introduced you to php dynamically generating objects based on string names, then we The content introduced today is similar to the content in the previous section. It is also the development of PHP using string names to call classes!
Step 1: First download the php we need to use for this lesson and use the name of the string to call the class library://m.sbmmt.com/xiazai/leiku/605
Step 2: After the download is complete, find the php class library file, extract it to the local directory, and then create a new file~
The third step: We call this class in the new php file and instantiate it:
<?php include_once "stringdiaoyong.php"; //引入类文件 $game = new Game(); //实例化列 //方法1,使用call_user_func call_user_func(array($game, 'Play'), 1); //方法2 $game->{'Play'}(2); //或者 $method = 'Play'; $game->$method(3); ?>
The final running result is as follows:
The above is the detailed content of PHP uses the name of a string to call a class development idea sharing. For more information, please follow other related articles on the PHP Chinese website!