How to access variables in other files in php files

Source: Internet
Author: User
Php class file how to access variables in other files I declare two files, one class file (123. class. php), a common file (index. php, the code is as follows), 123. class. how to obtain index in php. the value of $ abc in the PHP file (which is not included in the class file and cannot be obtained) 123. class. php code is as follows: PHPcode php class file how to access variables in other files
I declare two files, one class file (123. class. php), a common file (index. php, the code is as follows), 123. class. how to obtain index in php. $ abc value in the PHP file (the class file is not included directly and cannot be obtained)

123. the class. php code is as follows:
PHP code
  
  


Index. php code:
PHP code
  
  


Instantiation code:

$ Abc = new a123;
$ Abc-> index ();

------ Solution --------------------
Include ('index. php ');
Class a123 {
Public function index {
Global $ aa, $ bb; // or include ('index. php ');
Echo $ aa;
Echo $ bb;
}
}
------ Solution --------------------
Global

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.