The scope of include file variables in php ,. In php, we sometimes need to include a file. For example, when I was writing a framework some time ago, I planned to use native php as a template to study the scope of include file variables in php,
In php, we sometimes need to include a file. For example, when I was writing a framework some time ago, I planned to use the native php as the template and then write a display method to introduce the template file. but this is just my obscenity.
After writing the code, all the variables in the template are prompted to be undefined. The scope of the include file is summarized through various research and searching materials.
First case: file A includes file B. in file B, you can call the variable in file.
File A code:
File B code:
The output content is normal.
The second case: file A includes file B, and then the variable of file B can be called in file.File A code:
File B code:
At this time, the content can be output normally.
Case 3: Call file B in A method of A class in file A, and then call the variables in this method in file B.File A code:
show();
File B code:
At this time, the content can be output normally.
Case 4: File A Introduces file B through A defined function. in file B, variables in file A cannot be used, but variables in function (display) can be called in file.File A code:
File B code:
After running $ aaa, the prompt is undefined. $ bbb can be output normally.
Link: http://www.cnblogs.com/dragondean/
Therefore, it is not feasible for me to use a display method to introduce the template. Based on the three situations, I finally chose to write a class to import the template file. Currently, both ThinkPHP and Smarty use classes to introduce template files. If you have any shortcomings, please confirm them.
In php, we sometimes need to include a file. For example, when I was writing a framework some time ago, I planned to use native php as a template...