Re: where to put a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 14, 2008 at 11:34 AM, Rick Pasotto <rick@xxxxxxxx> wrote:
> Probably been answered a thousand times; if so, just tell me where to
>  look.

    The archives are always your best friend when searching for
specific data.  The two best are:
        http://www.marc.info/
        http://www.gmane.org/

>  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?

    If you only want to include it on one page, and then especially if
there are no includes in that page as of yet, then keep it in the same
file.  It'll be completely portable and self-reliant, which will keep
execution time (and resource usage) to the minimum possible amount.
If you plan on extending the site in the future and think you'll reuse
the function, place it in an include file site-wide.

>  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?

    There's not a great deal of overhead with including unused
functions aside from general syntax and parse checking via the
runtime.  For example, even though a function isn't called, if there's
a missing ) on a non-commented line, it'll fail fatally.  Unless you
have thousands of lines of functions, the benefit will probably
outweigh the cost in most situations.

-- 
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux