Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7953 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98115 invoked by uid 1010); 18 Feb 2004 14:44:30 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 98078 invoked from network); 18 Feb 2004 14:44:30 -0000 Received: from unknown (HELO moutng.kundenserver.de) (212.227.126.185) by pb1.pair.com with SMTP; 18 Feb 2004 14:44:30 -0000 Received: from [212.227.126.162] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1AtSw9-0002qE-00; Wed, 18 Feb 2004 15:44:29 +0100 Received: from [217.160.91.103] (helo=php.net) by mrelayng.kundenserver.de with asmtp (TLSv1:RC4-MD5:128) (Exim 3.35 #1) id 1AtSw9-0008El-00; Wed, 18 Feb 2004 15:44:29 +0100 Message-ID: <40337A3A.8040308@php.net> Date: Wed, 18 Feb 2004 15:44:10 +0100 Reply-To: hartmut@php-groupies.de User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7a) Gecko/20040111 X-Accept-Language: en, de MIME-Version: 1.0 To: Pierre-Alain Joye CC: internals@lists.php.net References: <20040218152756.1f958513@localhost.localdomain> In-Reply-To: <20040218152756.1f958513@localhost.localdomain> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:4d0d1aa686edf46be04a942500a6c0af Subject: Re: [PHP-DEV] HEAD, include(_once), bug in variable declaration From: hartmut@php.net (Hartmut Holzgraefe) 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 > -------- > $foo = "var from include"; > ?> > > testinc.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