Say, for example, I have 3 classes:
CODE
class base
{
function base_function()
{
echo 'hello world!';
}
}
{
function base_function()
{
echo 'hello world!';
}
}
CODE
class middle
{
function middle_function()
{
echo 'hello there!';
}
}
{
function middle_function()
{
echo 'hello there!';
}
}
CODE
class extension extends base
{
function func()
{
echo 'bye';
}
}
{
function func()
{
echo 'bye';
}
}
"base" is my base class, and "extension" extends "base". "base" will also contain an instance of "middle":
CODE
$base = new base;
$base->middle = new middle;
$base->middle = new middle;
However, I seem to be getting an error when I try to access "middle" and it's methods from within "extension":
CODE
class extension extends base
{
function func()
{
$this->base_function()
$this->middle_function();
echo 'bye';
}
}
{
function func()
{
$this->base_function()
$this->middle_function();
echo 'bye';
}
}
So this would be my code:
CODE
$base = new base;
$base->middle = new middle;
$extension = new extension;
$extension->func();
$base->middle = new middle;
$extension = new extension;
$extension->func();
... and I expect this from the output:
QUOTE
hello world!
hello there!
bye!
hello there!
bye!
But the error is:
QUOTE
Call to a member function on a non-object
(referring to the line containing $this->middle_function(); )
I've seen this error before obviously, but I'm not sure why I'm getting it. "middle" has been initialized through "base", and I can access methods etc in "base" okay, it just seems PHP doesn't like me touching objects that "base" has created.
Does that make sense?