It wrks okay here; I guess i'm keeping register_global= On in php.ini !

Try debuging your sample using get_declared_classes and you'll find what
you're missing

class overall {

var $loaded;

function load($class){

eval ("global \$$class;");

eval("\$$class = new $class;");

print_r(get_declared_classes());

return true;

}

}

----- Original Message -----
From: "Tularis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 19, 2002 10:50 AM
Subject: [PHP] OOP - transfering object-pointer


> Currently, I have the following code:
>
> <?php
>
> class overall {
> var $loaded;
>
> function load($class){
> //eval("global \$$class;"); // This didn't work either
> $this->loaded[] = $class;
> eval("\$this->$class = new $class;");
> return true;
> }
> }
>
> class foo {
> var $bar;
>
> // Constructor
> function bar(){
> if(!isset($this->bar)){
> $this->bar = 1;
> }else{
> $this->bar++;
> }
> echo $this->bar."<br>";
> }
> }
>
> // Start actual loading
> $overall = new overall;
> $overall->load('foo');
>
> foreach($overall->loaded as $key=>$val){
> $key =& $overall->$key;
> }
>
> $overall->foo->bar();
> $overall->foo->bar();
> $overall->foo->bar();
> $overall->foo->bar();
>
> // it doesn't understand this
> $foo->bar(); // line 42
> ?>
>
> It all works, except for the $foo->bar(); thing... I am wondering how I
> can turn $overall->foo->bar() to $foo->bar(); as all the things I've
> tried, don't work, they don't give any errors, except for
> Fatal error: Call to a member function on a non-object in
> d:\apache\htdocs\classes.php on line 42...
>
> Could anyone help me with this?
> thanx
>
> - Tularis
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


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

Reply via email to