"Daniel Barbar" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I'm almost ashamed to ask this question as surely enough the > problem is something very basic but, nonetheless, I can't put my finger on > it. I'm trying to implement the concept of a library (library.php) on PHP > where I define (once) all auxiliary functions and then use them in a file > (for instance index.php) via the 'require' or 'include' constructs. Here's a > reduced version of what I'm doing: > > > > index.php: > > <?php > $lang = (isset($_REQUEST['lang']) ? $_REQUEST['lang'] : "es"); > echo "index.php: include_path is " . (ini_get('include_path'))."<br>"; > require("http://tristan/library.php?lang=$lang"); > my_function("en"); > ?> > > > > library.php: > > <?php > echo "library.php: Called with $_SERVER[HTTP_HOST]:/$_SERVER[REQUEST_URI] > <br>"; > function my_function($lang = "es") { > echo "my_function() says $lang"; > } > echo "library.php: loaded<br>"; > ?> > > > > When I load index.php I get the following: > > > > index.php: include_path is .:/usr/local/php/4.3.6/lib/php > library.php: Called with tristan://library.php?lang=es > library.php: loaded > > > > Fatal error: Call to undefined function: my_function() in > /www/htdocs/index.php on line 5 > > > > It seems that the name space on index.php never gets updated > with the function definitions made on library.php. What am I doing wrong? > Thanks! Cheers, > > > > Daniel
Hi Daniel, take a look at this section of the manual about including remote files: >>> If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix J for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script. <<< Try including it as a local file: require_once library.php'; // if it is in the same directory as the file you have this line in Also you don't have to pass $lang via Get to the file as the included code will have access to $lang as it is then in the scope of the script. Regards, Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php