phpbar.de logo

Mailinglisten-Archive

[php] Method from Class from Class from Class

[php] Method from Class from Class from Class

P. Genna Privat genna.p.p at tat-world.de
Die Mai 6 15:55:01 CEST 2008


Im Kopf macht es Sinn,
aber warum gehts trotzdem nicht?
Code selbsterklärend:

<?php
class main {
    public function set($class){
        $this->$class = new $class;
    }
}

class math{
    public function add($a, $b){
        return $a + $b;
    }
}

class view extends main {
    public function show($a, $b){
        echo $this->math->add($a, $b);
    }
}
$run = new main;
$run->set("math");
$run->set("view");
$run->view->show(5,6);
?>

Ergibt:
*Fatal error*: Call to a member function add() on a non-object

?


php::bar PHP Wiki   -   Listenarchive