PHP conditional include statement parsing
I’m writing some PHP and using include statements as is pretty common. When using conditional includes in my code I wasn’t quite sure whether the content of the included file is included regardless and then ignored or is only included conditionally (which of course would be the better option from a memory consumption perspective and so on), so I set out to find some info about PHP conditional includes, but surprisingly it wasn’t so easy to find.
I’ve finally managed to come across this PHP Include article that confirm what I was hoping for and also something that I didn’t know. Apparently when an include is conditional, the content won’t be included if the condition evaluates to false, while if you use a require the content will be included but will not execute. The last statement seems a little weird since I would expect that if logic is used to work out the source for the require statement that source might not exectute because it’s inside the conditional block, but that may be the exception.
Anways, it’s good to know that files which are conditionally included won’t get parsed.