Re: Global or include?

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

 



In that case you should use include_once in every script. But if you are absolutely sure that all scripts will be processed, you can include it only in one of them, because PHP - in short terms - does a file include, so it will look like as the included file is part of the script. The global keyword does not do what you think, it only propagates variables between functions without passing them as parameters. In general, you ought to avoid using global, because it can make your script less readable, and / or can lead to logical errors.

Because I am OOP fan, I'd rather create a static class, using public static fields, so you can reach those variable as like ConstClass::MyConstant. In that way, you have the advantage of simply create new constants, and it doesn't matter how many times you include this file, there will be only one instance.

SanTa

2011.01.05. 23:40 keltezéssel, Paul Halliday írta:
Say you have 10 or so scripts and a single config file. If you have
main.php, functions1.php, functions2.php, functions3.php..

Does is hurt to do an include of the config file in each separate
script, even if you only need a few things from it,  or should you
just specify what you want with a 'global' within each
script/function?

Thanks!


<<attachment: smime.p7s>>


[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