Re: where to put a function
| From: | Nathan Nobbe | Date: | Mon, 14 Apr 2008 15:44:41 +0000 |
| Subject: | Re: where to put a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272977@lists.php.net to get a copy of this message | ||
On Mon, Apr 14, 2008 at 9:34 AM, Rick Pasotto <rick@niof.net> wrote:
> 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?
each have their merits and detriments.
1. down-and-dirty, if you put it here, you may have to move i later
2. more organized, somewhat future conscience, because now it can already be
used by other code simply by including the file
3. hmmm. well, i would only put it in a file w/ other functions related to
it. if you have a small app it could make sense to just toss a bunch of
seemingly random functions together in one file, but after a while that
could get pretty messy.
What is the cost of parsing a
> bunch of functions that are not used on a given page load?
>
not much, but less if you have an opcode cache. i would be more worried
about code organization than performance on this one.
-nathan