Re: calling functions from one or multiple files

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

 



On Wed, Sep 24, 2008 at 12:28 PM, Lamp Lists <lamp.lists@xxxxxxxxx> wrote:
> Hi,
> Right now I use one file, usually called functions.php, with all functions I'm going to use most likely on every page.
> Then, I create each function I'm going to use once in a while as separate file.
> Pro: I would include a function when I'm going to use.
> Con: I have to write extra include line to call function. And have bunch of files (functions) in function folder.
>
> I was talking to co-workers few days ago and they said I complicate my
> life to much and putting ALL functions in one file is just fine and
> I'll not be able to see difference in "real situations".
>
> True?
>
> -ll
>
>
>
>

I work with functions much the same way that I work with classes.
When I'm forced to work on procedural code I always prefix the
namespace onto it.  Let's take a very generic shopping cart example.
There's going to be products and a cart.

Here are the files/prototypes:

/code/storeappname/item.php
function storeappname_item_load(int $id);
function storeappname_item_save(array $item);
function storeappname_item_delete(int $id);

/code/storeappname/cart.php
function storeappname_cart_add_item(array $item);
function storeappname_cart_remove_item(int $id);
function storeappname_cart_calculate_totals();

I'd set /code into the include path.  Depending on what page you're on
you just include the function files that you know you're going to use
like require_once 'storeappname/cart.php', etc.  Too bad there's not
an autoload for functions.

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