Solution to global failure caused by multiple php include operations

Source: Internet
Author: User
This article mainly introduces the solution to global failure of global variables caused by multiple php include operations. The example analyzes the principle and solution of $ GLOBALS failure, which has some reference value, for more information, see

This article mainly introduces the solution to global failure of global variables caused by multiple php include operations. The example analyzes the principle and solution of $ GLOBALS failure, which has some reference value, for more information, see

This article describes how to resolve global failure caused by multiple php include operations. Share it with you for your reference. The specific analysis is as follows:

In multiple files, the file is included one by one, but the functions in the last file use global, but the global variables cannot be referenced. For example:
A. php file:

<? Php $ aa = 1;?>

B. php file:

<? Phpinclude a. phpfunction show () {global $ aa; var_dump ($ aa) ;}?>

Display: null;

This failure is caused by multiple reasons. An effective method is to use the $ GLOBALS array if you decide to treat a variable as a global variable of multiple files. For example, in the example above, a. php:

<? Php $ GLOBALS ['aa'] = 1;?>

Then you can reference this variable in functions and methods of multiple files.

I hope this article will help you with php programming.

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.