include file in a class with global/parent scope?
| From: | Daniel Kolbo | Date: | Sun, 14 Jun 2009 16:41:32 +0000 |
| Subject: | include file in a class with global/parent scope? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-294030@lists.php.net to get a copy of this message | ||
Hello,
I understand the why $vars is not in the global scope, but i was
wondering if there was a way from within the class file to include a
file in the parent's scope?
i tried ::include('vars.php'), parent::include('vars.php'), but this
breaks syntax...
Please consider the following three files:
'scope.class.inc'
<?php
class CScope {
public $var = 'class scope\n';
function cinclude($filename) {
include('vars.php');
echo "In class $vars\n";
}
}
?>
'vars.php'
<?php
//global $vars;//if this line is uncommented then the desired result is
achieved however, i don't want to change all the variables to global
scope (this file is includeded in other files where global scoped
variables is not desireable).
$vars = 'vars.php scope\n';
?>
'scope.php'
<?php
include('scope.class.inc');
$object = new CScope;
$object->cinclude('vars.php');
echo "In original $vars\n";//$vars is not defined***
?>
Thanks,
dK