Re: where to put a function

From: Date: Tue, 15 Apr 2008 19:01:14 +0000
Subject: Re: where to put a function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-273008@lists.php.net to get a copy of this message
Rick Pasotto írta:
Probably been answered a thousand times; if so, just tell me where to look. I have a function that includes a specific sql query that is used on only one page on the site. Should that function be coded (1) in the page itself, (2) in a separate file that only that page includes, or (3) in a master file that contains all the functions used on the site and is included on every page? I've been doing #1 (not actually a function in this case) but #3 is appealing, especially since I would implement it as OOP and the page itself would be really just a template. What is the cost of parsing a bunch of functions that are not used on a given page load?
Q: where to put a function? A: into the class where it belongs. sorry I could not stand it ;) to be more serious, one giant 'functions.php' include file is not a very good solution, because you might end up including dozens of unused functions in every page. on the other hand, putting it into the page doesn't let you use it anywhere else. so the solution should be somewhat like the oop class organization: put together those that are logically belonging together. this way you'll have libraries for each type of functions, and only include what you need greets, Zoltán Németh

« previous php.general (#273008) next »