Reputation:
Do functions parse the code when they are called or are they loaded even if the function isn't be called? Sorry if it seems like a newbie question, I'm just curious about this.
Thank you
Upvotes: 0
Views: 60
Reputation:
All code in a PHP file is parsed and converted to PHP bytecode before any of it is run.
For instance, a PHP file with a syntax error anywhere in it will fail to run at all, even if the syntax error isn't anywhere near the part that is being run.
Upvotes: 1
Reputation: 6353
They do not "process their code" until they are called. For example:
function my_function() {
return "Hello World";
}
The above will not execute until you call it:
echo my_function();
With that said, the code in your function still needs to be valid or it will cause errors.
You may want to read the User-defined functions or W3 Schools PHP Functions.
To keep the script from being executed when the page loads, you can put it into a function. A function will be executed by a call to the function.
Upvotes: 1