Using class called within a function of an extended class pr
Posted: Thu Apr 08, 2010 7:07 pm
I'm trying to initialize a class within a function that is inside a class and use that class within an extended class, but having a problem with the extended class not being able to find it. Not the exact code I'm using, but same structure:
But I get a "Call to a member function function() on a non-object" error.
It works if I do this, but I would prefer not to have to do it if I don't have do:
Code: Select all
class A {
function test() {
$this->class = new class;
}
}
class B extends A {
function B() {
$this->class2 = new C;
}
}
class C extends B {
function C() {
$this->class->function();
}
}
It works if I do this, but I would prefer not to have to do it if I don't have do:
Code: Select all
class C extends B {
function C() {
global $a;
$a->class->function();
}
}