Class and variable scope
| From: | Gerard Samuel | Date: | Mon, 19 May 2003 18:16:55 +0000 |
| Subject: | Class and variable scope | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-148191@lists.php.net to get a copy of this message | ||
Im declaring a variable in a class constructor, and then including another file which depends on this declared variable.
In this included file, the variable behaves as if it wasn't even set.
I've provided some mock code to explain what Im using.
If you need more info, feel free to ask. Thanks.
Class file
-----
<?php
class Class
{
function Class()
{
$foo = 'some-value';
include('./bar.php');
}
}
?>
bar.php
-------
<?php
global $foo;
if (!isset($foo))
{
$foo = 'some-default-value';
}
var_dump($foo); // <- Shouldn't $foo be 'some-value' instead of 'some-default-value' here?
?>