Re: [PHP] include file in a class with global/parent scope?

[email protected] (Daniel Kolbo)
Newsgroups php.general
Message-ID <[email protected]>
Martin Scotta wrote:
> Where is $vars? there is no $vars in your code...
> 
> You can extract all the global space in the CScope method, it's quite
> simple, but less performant.
> 
> 
> class CScope {
> 
>        public $vars = 'class scope\n';
> 
>        function cinclude($filename) {
>                extract( $GLOBALS );
>                include('vars.php');
>                echo "In class $vars\n";
>        }
> }
> 
> On Sun, Jun 14, 2009 at 1:41 PM, Daniel Kolbo <[email protected]
> <mailto:[email protected]>> wrote:
> 
>     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 $vars = '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
> 
>     --
>     PHP General Mailing List (http://www.php.net/)
>     To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 
> -- 
> Martin Scotta

replace all $var with $vars.  The extract method proposed is the
opposite of what i'm looking to do.  I want to bring the class's include
scope into the calling object's scope.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.