Hello everyone!
I've been struggling with some code for several days now, I've tried everything that I can think off and nothing works as I want, maybe it isn't even possible but it's being a real pain in the ass.
Here is my problem: I've a class named Framework, this class constructor instantiates another class named Loader, that, therefore instantiates all the other classes I need. See my code below.
<?php
class Framework
{
function Framework()
{
$this->Loader = new Loader();
$this->Loader->Library('Benchmark');
// This is the kind of behavior that I expect
//$this->Benchmark->SayHi();
// This is how it works...
$this->Loader->Benchmark->SayHi();
}
}
/*
* class Loader extends Framework gives me a 404 page - anyone knows why?
*/
class Loader
{
function Library($library)
{
/*
I've also tried to do:
$foo = get_parent_class($this);
$$foo->Load->Library('Benchmark');
but it doesn't even instantiates the object....
*/
$this->$library = new $library;
}
}
class Benchmark extends Framework
{
function Benchmark()
{
echo "my parent is " . get_parent_class($this) . "<br />\n";
}
function SayHi()
{
echo "Hello my dear friends!<br />\n";
}
}
$framework = new Framework;
echo "<pre>";
print_r($framework);
echo "</pre>";
/*
OUTPUT:
my parent is Framework
Hello my dear friends!
Framework Object
(
[Loader] => Loader Object
(
[Benchmark] => Benchmark Object
(
)
)
)
*/
?>
How can I instantiate objects with the Loader class and have them being children of Framework, so I can access them with a syntax like $framework->OBJECT->METHOD? I'm coding for PHP4.
All solutions are welcome. Thanks!
Yours truly,
Alix Axel