$overall->foo->bar() works for me.
also there's no need for the eval('global...') line
Apache 1.3.27, PHP 4.2.2
-js
Tularis wrote:
> ok, I have gotten great help here already, but it still doesn't work,
> it returns a object not found error (on the $foo->bar() line). I want to
> change $overall->foo->bar() to $foo->bar... any tips? or help??
>
> thanx!
> - Tularis
>
> <?php
>
> class overall {
> var $loaded;
>
> function load($class){
> eval("global \$$class;"); // This didn't work either
> //$this->loaded[] = $class; // see the comments with the foreach()
> 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){ // didn't work.. I commented
> this out, because I thought it MIGHT interfere with the other way
> $val =& $overall->$val; // both don't work though :(
> }
> */
>
> $overall->foo->bar();
> $overall->foo->bar();
> $overall->foo->bar();
> $overall->foo->bar();
>
> // it doesn't understand this
> $foo->bar();
> ?>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php