just change make your new class global :
class overall {

var $loaded;

function load($class){

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

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

return true;

}

}

then you can call it using
$overall = new overall;

$overall->load('foo');

// This should work now ;).

$foo->foo();



Hatem

----- Original Message ----- 
From: "Tularis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 17, 2002 11:21 PM
Subject: [PHP] OOP-classes in PHP


> currently I have the followig script:
> 
> everything works fine, except for the fact that it doesn't seem to 
> understand $overall->foo->foo();. It returns this error:
> "Fatal error: Call to a member function on a non-object in 
> d:\apache\htdocs\classes.php on line 32"
> 
> Now, I know the object is loaded, because the constructor is run, and 
> puts out a 1 onscreen... I wish to know how to make this work...
> any help plz?
> 
> thanx
> - Tularis
> <?php
> 
> class overall {
> var $loaded;
> 
> function load($class){
> eval("\$$class = new $class;");
> return true;
> }
> }
> 
> class foo {
> var $bar;
> 
> // Constructor
> function foo(){
> if(!isset($this->bar)){
> $this->bar = 1;
> }else{
> $this->bar++;
> }
> echo $this->bar."<br>";
> }
> }
> 
> // Start actual loading
> $overall = new overall;
> $overall->load('foo');
> 
> // As of here it won't work anymore... somehow $overall->foo-> doesn't 
> work...
> 
> $overall->foo->foo();
> ?>
> 
> (and if possible, I would also like to change $overall->foo->foo() to 
> $foo->foo(), but still keeping that class as a 'subclass' to the overall 
> one.)
> 
> 
> -- 
> 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