A description of the scope of the PHP include variable

Source: Internet
Author: User
Author: zhanhailiang Date: 2015-04-17

First, read the include, which highlights that the code included in the include inherits the variable scope of the Include row:

When a file is contained, the code contained in it inherits the scope of the variable for the row in which the include is located. From there, any variables that are available to the calling file at that line are also available in the called file. However, all functions and classes defined in the include file have global scope.

This means that the code in the include can access all of the related variables that are accessible to the line where they are located.

As below, I will write test.php test1.php to verify a very odd notation:

test.php

 
   

test1.php

  
  A = 1;                                                                                 

The execution output is as follows:

Object (a) #1 (2) {  ["a"]=>  int (1)  ["B"]=>  int (2)}

This proves that the code in the include file does inherit the range of variables from the include row, which can be accessed to the $this variable.

  • 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.