Question

Reading over the documentation about include_once it basically says that the file in question won't be re-included if it's included already.

Can I equate this in my head as a static instance of the script, or will this lead me to trouble down the road?

EDIT

Not looking for a tutorial on include_once, I understand it quite well. Would like to know if I can conceptually attach the properties and characteristics of a static member, to this idea.

EDIT 2

Would the downvoters care to explain? It's a conceptual question, with a clear answer.

Was it helpful?

Solution

I'm not sure how the actual function works, but the best way to think about it is:

"If this file has been included/required earlier in this stream, no need to include/require it again."

The point is to avoid including a file that "redefines" a class or function because it was already defined in that same file included earlier.

The important thing to keep in mind is the idea of the script (and any included scripts along the way) as having a start and a finish. Any calls to include_once checks if that file has already been included since the start of the whole script. If it has, it doesn't bother to include it again, it just goes off of the originally included file.

Once the script is finished (no work left to be done, stream is closed, interrupted, aborted, etc), then re-starting the process treats the first include/include_once of a file as the first include, since it's the first time it's been included since the new running of the script. In that case, your back to square one, with all values being set back to default or unset.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top