Re: Including file Inside class
- From: briandichiara <briandichiara@xxxxxxxxx>
- Date: Mon, 8 Sep 2008 11:18:39 -0700 (PDT)
Right now, i have found this solution by adding
extract($GLOBALS);
to the top of my function.
I would now like to somehow get the variables inside the include file
back into the global variable scope, making this function work just
like a normal include file. Is that possible?
On Sep 8, 11:35 am, briandichiara <briandichi...@xxxxxxxxx> wrote:
I'm trying to setup a class that will allow a file to be included on
the page. It goes something like:
<?php
class myClass {
... ... ...
function includeFile(){
if(file_exists($this->include_file)){
include($this->include_file);
} else {
$this->error("file missing");
}
}
... ... ...
}
$foo = "bar";
$page = new myClass();
$page->include_file = "the_file.php";
$page->includeFile();
?>
// the_file.php
<?php echo $foo; ?>
It has something to do with variable scope and accessing globals or
something, I'm not sure. My question is how should I setup my class so
that I do not have to use "return" at the bottom of any files I want
to include with my class? I want the includes to function just like
normal includes.
I tried
<?php
class myClass {
... ... ...
function includeFile(){
global $GLOBALS;
global $HTTP_SERVER_VARS;
if(file_exists($this->include_file)){
include($this->include_file);
} else {
$this->error("file missing");
}
}
... ... ...
}
but that still doesn't make $foo print "bar".
Thanks for any help on how to accomplish this.
.
- Follow-Ups:
- Re: Including file Inside class
- From: Jerry Stuckle
- Re: Including file Inside class
- References:
- Including file Inside class
- From: briandichiara
- Including file Inside class
- Prev by Date: Re: How to use Password() in PHP? Syntax problem?
- Next by Date: Re: PHP has encountered an access violation...
- Previous by thread: Including file Inside class
- Next by thread: Re: Including file Inside class
- Index(es):
Relevant Pages
|