Variables in files introduced by phpinclude_once cannot be used.

Source: Internet
Author: User
Assume that the content in one file named test1.php is {code...} and the content in another file named test2.php is {code...}. Then, access the test2.php program and report that the variable is not found. Excuse me, what do you think we should do? Test1.phpFile Content



  

The content of another file named test2.php



  

Then access the test2.php program and report that the variable is not found.
What are the solutions to these problems?

Reply content:

Assume thatTest1.phpFile Content



  

The content of another file named test2.php



  

Then access the test2.php program and report that the variable is not found.
What are the solutions to these problems?

In PHP, global variables cannot be directly called in functions. In this Code, if you want to call $ a in the test function, you should first declare it with global.

Function test () {global $ a; echo $ ;}

A local variable in a function and a global variable may be faulty! We recommend that you first learn the definitions of local variables and global variables.

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.