PHP parses includes inline, so whatever the scope is where the file is
included, is the scope of the variables that the include contains.  You can
declare the variables global in your fuction and it will use what was
included, that would be the quick fix, you could also switch your include to
use DEFINE instead of just instantiating variables. Constants have global
scope.

> -----Original Message-----
> From: Mike Tuller [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 04, 2003 12:25 PM
> To: php mailing list list
> Subject: [PHP] Includes confusion
>
>
> I can't figure this out. I have a line where I include a file
>
> include "/Library/WebServer/includes/database_connection.inc";
>
> I want to have this declared in one location, so that I don't have to
> change multiple lines if I ever move the application, everything works
> fine except inside functions. So if I have the following:
>
> include "/Library/WebServer/includes/database_connection.inc";
>
> function list_search_results()
> {
>       // my code that lists search results
> }
>
> The functions returns an error, but if I do this:
>
>
> function list_search_results()
> {
>       include "/Library/WebServer/includes/database_connection.inc";
>       // my code that lists search results
> }
>
> Everything works fine. Shouldn't the function be able to use the
> include file when it is declared outside the function?
>
> Mike
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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

Reply via email to