On 8/20/07, Augusto Morais <[EMAIL PROTECTED]> wrote:
> I dont know what is happening...
>
>
> Can somebody clarify the situation for me?
>
>
> here is the situation:
>
>   i have 3 files:
>
> class.php
> foo.php
> bar.php
>
> // - class.php
> class globalactions {
>
>      function include_file($module) {
>                if ($module) {
>                        return 
> ("modules/".$module."/templates/".$module.".php");
>                } else { return include("modules/main/templates/index.php"); }
>      }
> }
>
>
> // - foo.php
> include "lib/clients.class.php";
> $clients = new clients(); //instatiating the clients class
>
>
> // - bar.php
> include 'class.php';
> $globalactions = new globalactions ();
> include $globalactions->include_file("foo");  //return ->
> "modules/foo/templates/foo.php"
>
> var_dump($clients); //will return the object
>
>
>
> OK. All this works. but i want make some changes.
>
> Well.. What i want to do is this:
>
> class.php:
>
> change the line:
> return ("modules/".$module."/templates/".$module.".php");
>
> to:
> return include ("modules/".$module."/templates/".$module.".php");
>
> and in the bar.php:
>
>
> // - bar.php
> include 'class.php';
> $globalactions = new globalactions ();
> $globalactions->include_file("foo");  //return -> "include
> modules/foo/templates/foo.php"  // OK. This works.
>
> var_dump($clients); //i dont get the object here. I got NULL!!! why?!?!!?
>
>
>
> What is happening?
>

This is because in the second example, you're including the file in a
different scope than the first example. The file included (and so all
variables etc. declared in it) will be added to the scope where the
include is.

This manual page should help you:
http://www.php.net/manual/en/language.variables.scope.php

Tijnema
-- 
If this is a mailing list: DO NOT TOP POST! why?:
http://www.caliburn.nl/topposting.html

Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to