ID: 26174
Updated by: [email][/email]
Reported By: myle34 at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Variables related
Operating System: Windows XP Home
PHP Version: 5.0.0b2 (beta2)
New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the doentation available at
[url][/url] and the instructions on how to report
a bug at [url][/url]

when you include a file within a function/method , the global code is
in the function/method scope.

therefore $foo is in the function scope... (not global)..

functions/classes/methods you define in there however are defined

Previous Comments:

[2003-11-08 02:30:56] myle34 at hotmail dot com

This is related to Bug #26173 ([url][/url])
but the reproduce code was wrong.

I am using Windows XP Home and Apache 2.0.47 with PHP beta 2.

This bug is related to function/class/global scopes.

Note that if you merge foo.php and bar.php (foo.php and right after
that bar.php) (ie. without the include_once), this will work as

I haven't tested this with include but I suspect it would have the same

Reproduce code:
// foo.php
class TestOne {
function __construct() { include_once 'bar.php'; }
$TestOne = new TestOne();

// bar.php
// uncommenting this makes it work
// global $foo;
$foo = 'bar';
// uncommenting this does nothing
// global $foo;
function TestTwo() {
global $foo; echo $foo;

Expected result:

Actual result:
No output


Edit this bug report at [url][/url]