include (or require) doesn't seem to work
| From: | Daniel Barbar | Date: | Tue, 11 May 2004 17:25:59 +0000 |
| Subject: | include (or require) doesn't seem to work | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-185938@lists.php.net to get a copy of this message | ||
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