arborint wrote:I am not sure what does not work? Are you trying to call it statically? I just ran the following on a 4.3 box and it worked fine.
Code: Select all
<?php
$willitwork = new Some_Class();
$willitwork->some_something();
class Some_Other_Class {
function Some_Other_Class()
{
//just example
}
function boo()
{
return true;
}
}
class Some_Class {
function Some_Class()
{
$this->foo = new Some_Other_Class;
}
function some_something()
{
if($this->foo->boo())
{
echo "true";
} else {
echo "false";
}
}
}
Yes that does work fine, as said above.
When using extenstions it does not work, as Ole points out.
Now I am trying to figure out how to make the 'idea' work if using extensions.
Code: Select all
$willitwork = new Some_Class_Ext();
$willitwork->some_something();
class Some_Class {
function Some_Class()
{
$this->foo = new Some_Other_Class;
}
function some_something()
{
if($this->foo->boo())
{
echo "true";
} else {
echo "false";
}
}
}
class Some_Class_Ext extends Some_Class
{
function Some_Class_Ext()
{
//just example
}
}
class Some_Other_Class {
function Some_Other_Class()
{
//just example
}
function boo()
{
return true;
}
}
if I made
$foo a global inside each method, then the above would work.
However, that is a nasty way of doing it and I'm trying to learn a proper way to use extends.
Maybe instead of calling externally:
Code: Select all
$willitwork = new Some_Class_Ext;
$willitwork->some_something();
Call it internally where ever needed?