简体   繁体   中英

Does an include execute the PHP code of the included file?

如果是,此代码是在包含它的文件的代码之前执行还是并行执行?

It evaluates all the php file in the line you write the include .

Here's a piece of the manual:

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

For more info: include manual

There are a few things i'm missing from the question, but basically, yes. PHP will execute code inside of the PHP file if included, that is what PHP does. it executes to output code to the browser. If you do not want it to execute the code, I would suggest wrapping it in a function or sending an ajax call to the page when you are ready to execute it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM