This is essentially a really long question

If I were to create a function without calling it's execution. Does PHP initialize it anyhow or is the entire function ignored entirely without even bothering to read it?

Another way to put it:

Is there any execution difference between code that does have function Example() defined and one that doesn't? In both cases when it's not called?

(don't ask "WHY WOULD YOU NEED TO KNOW IT", just, just, just, just, just, just, just, just, just, answer, just answer)

Recommended Answers

All 2 Replies

I think it's valuable information.
As far as I can tell there is no cost to initialising/defining/loading a function that is never used. That is, PHP doesn't do anything to it until it is called. But I could be wrong.
However, a larger file does have a higher cost involved when it is loaded than a smaller one. Say you include your file and there are a lot of dead code functions in there. They still have to get loaded as they're part of the file and that comes at a cost.

Likely it's just the memory used by the script. While it may not be much when compiled down, it's still memory and cycles required to turn it into machine code and have the pointers available for reference.

If memory isn't an issue (in most cases it is not) and CPU cycles are not a major thing (on most web servers they are not), then you probably have little to worry about if your file size is fairly manageable. However, if you're loading Megabytes worth of dead function pointers, many would first ask why bother? Then, the potential hit will come from how fast the machine is (and what resources are availale), and if it is capable of processing that much data that quickly (in a shared rack space and/or on a VM, it may make a few eyebrows raise).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.