Function instantiation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iainh
Forum Newbie
Posts: 5
Joined: Mon Jan 25, 2010 3:48 pm

Function instantiation

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Function instantiation

Post 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.
iainh
Forum Newbie
Posts: 5
Joined: Mon Jan 25, 2010 3:48 pm

Re: Function instantiation

Post 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
Post Reply