Re: HEAD, include(_once), bug in variable declaration
| From: | Hartmut Holzgraefe | Date: | Wed, 18 Feb 2004 14:44:10 +0000 |
| Subject: | Re: HEAD, include(_once), bug in variable declaration | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7953@lists.php.net to get a copy of this message | ||
Pierre-Alain Joye wrote:
Hello,
Having the scripts pasted below:
include_once fails to declare the variable 'foo'. Replace include_once
by include and it works. I got the same behavior using require and
require_once.
Am I wrong to see that as a bug?
inc.php
--------
<?php
$foo = "var from include";
?>
testinc.php
-----------
<?php
function getFoo()
{
static $calls=0;
include_once 'inc.php';
$calls++;
echo "calls:$calls\n";
return $foo;
}
echo getFoo() . "\n";
echo getFoo() . "\n";
?>
it works for the first call to getFoo(),
on any following call include_once
will ignore "inc.php" as it was already
included before, and as $foo is a local
variable to getFoo() it won't exist in
any but the first call
remember that in PHP include is evaluated
at runtime, not at compile time ...
--
Hartmut Holzgraefe <hartmut@php.net>