Page 1 of 1

Function instantiation

Posted: Tue Jan 26, 2010 3:48 pm
by iainh
When does php perform the instantiation of a function:
  • When the file containing the function is first loaded?
  • When the function is first called?
I ask as I wonder about the relative merits of having a single/few includes that include all/most functions required and so minimising file I/O to load includes, vs. the 'weight' of parsing and instantiating a larger number of functions, not all of which may be required?

So a single/few include files each containing many functions means less file I/O and include loading, but (depending upon when php instantiates functions) may carry a penalty of parsing and instantiating many functions, some not required,

vs.

Numerous includes each only containing a few functions which may result in requiring multiple includes and so heavier file I/O, but only parsing and instantiating those functions actually required.

Anyone a view on this?

Re: Function instantiation

Posted: Tue Jan 26, 2010 5:04 pm
by requinix
There's no "instantiation" of functions. They aren't objects. But maybe you have the right idea and the wrong term.
In remotely recent versions of PHP they get parsed and loaded when the file is included - barring any sort of conditional interpretation, of course.

My style:
Group functions together in files as would make sense. That means don't combine I/O functions with database functions with net functions. You could even go more specific than that if you have many of a certain type.
Then require_once each file as you need it.

Re: Function instantiation

Posted: Wed Jan 27, 2010 3:22 pm
by iainh
No that makes sense and was as I was guessing...but it's not the kind of detail often documented. Or at least not that I've tripped over yet :-)

Thx