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  <[EMAIL PROTECTED]>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to