Re: PHPLib Include - Help!
| From: | jeremy brand | Date: | Tue, 02 Jan 2001 22:25:53 +0000 |
| Subject: | Re: PHPLib Include - Help! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32385@lists.php.net to get a copy of this message | ||
What I do is inside of a file that I include, I set a define for the
name of that include, so then when you need to include it you can do
if (!defined('MY_FILE_INC'))
include('my_file.inc');
This comes in very helpful when working in project groups when you
don't have control of other people's code.
Jeremy
Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: jeremy@nirvani.net
http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html
for more
Get your own Free, Private email at http://www.smackdown.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"<body>" -- Quoted from Yahoo! homepage, http://www.yahoo.com
On Mon, 1 Jan 2001, Matt Stone wrote:
> Date: Mon, 1 Jan 2001 13:07:16 +1000
> From: Matt Stone <matt@planetveggie.com>
> To: PHP List <php-general@lists.php.net>
> Subject: [PHP] PHPLib Include - Help!
>
> Hi,
> I developed at script on my server in which PHPLib was not automatically
> added to the head of my PHP files. This way I could manually include them
> and then check to see if the had been included as not to redeclare the class
> like so:
>
> if (!isset($LIBVAR) or !is_array($LIBVAR)){
> $_PHPLIB["libdir"] = "c:/inetpub/phplib/php/";
> include($_PHPLIB["libdir"] . "db_mysql.inc");
> class TheDB_Sql extends DB_Sql {
> var $Host = "*****";
> var $Database = "*****";
> var $User = "*****";
> var $Password = "*****";
> }
> $Db=new TheDB_Sql;
> }
>
> However I just installed the script on a different server where PHPLib is
> automatically added to the head of PHP files. So now I have something like
> this:
>
> if (!isset($LIBVAR) or !is_array($LIBVAR)){
> //$_PHPLIB["libdir"] = "c:/inetpub/phplib/php/";
> //include($_PHPLIB["libdir"] . "db_mysql.inc");
> class TheDB_Sql extends DB_Sql {
> var $Host = "*****";
> var $Database = "*****";
> var $User = "*****";
> var $Password = "*****";
> }
> $Db=new TheDB_Sql;
> }
>
> But here we have another problem. Seen as PHPLib is automatiaclly added,
> then
> if (!isset($LIBVAR) or !is_array($LIBVAR))
> will always return false. SO I change it to this:
>
> //if (!isset($LIBVAR) or !is_array($LIBVAR)){
> //$_PHPLIB["libdir"] = "c:/inetpub/phplib/php/";
> //include($_PHPLIB["libdir"] . "db_mysql.inc");
> class TheDB_Sql extends DB_Sql {
> var $Host = "*****";
> var $Database = "*****";
> var $User = "*****";
> var $Password = "*****";
> }
> $Db=new TheDB_Sql;
> //}
>
> But this as you can see is defeating the whole purpose and now the $Db=new
> TheDB_Sql; is executed multiple times and causing this error:
> Fatal error: Cannot redeclare class thedb_sql in
> /home/www/htdocs/planetveggie/namebank/libraries/secure.php
>
> Any ideas? Please help. Thanks,
>
> Matt Stone
>
> _______________________________
>
> This email may contain confidential and/or privileged information for the
> sole use of the intended recipient. Any review or distribution by others is
> strictly prohibited. If you have received this email in error, please
> contact the sender and delete all copies. Opinions, conclusions or other
> information expressed or contained in this email are not given or endorsed
> by the sender unless otherwise affirmed independently by the sender.
>
> _________________________________
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>