Here is the code layout outline all nicely laid out in 3 file and class’s
$aa = new className();
class className {
/**
* Constructor
*/
function className() {
$this->init_SubClass();
}
function init_SubClass() {
require_once('sub_class.class.php');
$sub_class = new sub_class();
}
}
sub_class.class.php
class sub_class {
/**
* Constructor
*/
function sub_class() {
$this->init_Sub_Sub_Class();
}
function init_Sub_Sub_Class() {
require_once('Sub_Sub_Class.class.php');
$Sub_Sub_Class = new Sub_Sub_Class();
}
}
sub_sub_class.class.php
class Sub_Sub_Class {
public function function_I_to_call() {
echo ' show this text'
}
}
How to a call function_I_to_call()
This was mybest guess so far
$aa->className->sub_class->function_I_to_call()
Not sure how to do this or if it can be done.
Many Thanks
You are not assigning the newly created object to the instance. You need to use
That will make them public properties and then you can use your
However, the entire approach is completely flawed:
__construct. The old style constructor is a relic from PHP4 times and wont work with namespaced classes.requireare unneeded when you use an Autoloader.Alternate approach
And then
BarAnd
Baz:And then assemble it via:
Or move that code to a Factory:
Finally, the Autoloader (simplified):
And then you could call (demo)
But you shouldnt (unless it’s some sort of DSL), because that is violating Law of Demeter because you are digging too deep into the collaborators.