PHP uses the name of the string to invoke the class's development ideas to share

Source: Internet
Author: User
Tags php class
Examples of PHP dynamically generated objects based on string class names in previous articles we introduce PHP to dynamically generate objects based on string names, so what we've introduced today is similar to the one in the previous section, and PHP uses the name of the string to invoke the idea of the class!

First step: First download the PHP we need for this lesson to use the name of the string to invoke the class library: http://www.php.cn/xiazai/leiku/605

Step two: Find the PHP class library file after download, unzip to the local directory, then create a new file ~

The third step: we call this class in the new PHP file, and instantiate:

<?phpinclude_once "stringdiaoyong.php"; Introduce class file $game = new game ();              Instantiate column//Method 1, using Call_user_func call_user_func (Array ($game, ' play '), 1),//Method 2$game->{' Play '} (2);//or $method = ' Play '; $game-$method (3);? >

The results of the final operation are as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.