Examples of Variable Functions in php

Source: Internet
Author: User

Examples of Variable Functions in php

Examples of php Variable Functions

The variable functions of php are summarized in the php manual and are of little use today;

PHP supports the concept of variable functions. This means that if a variable name has parentheses, 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 for some purposes, including callback functions and function tables.

Variable functions cannot be used for echo, print, unset (), isset (), empty (), include, require, and similar language structures. You need to use your own packaging functions to use these structures as variable functions.

Class Foo {function Variable () {$ name = 'bar'; $ this-> $ name (); // This callthe Bar () method} function Bar () {echo "This is Bar" ;}}$ foo = new Foo (); $ funcname = "Variable"; $ foo-> $ funcname (); // This CILS $ foo-> Variable () class Foo {static $ variable = 'static properties'; static function Variable () {echo 'method Variable called ';}} echo Foo: $ variable; // This prints 'static properties '. it does need a $ variable in this scope. $ variable = "Variable"; Foo: $ variable (); // This CILS $ foo-> Variable () reading $ variable in this scope.

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.