Hey all, im trying to call a member function of a class as a class variable and having some issues. Am i doing something wrong here? Heres an outline of what im doing, I get a fatal error on function test, it tells me that im calling testfunc on a non object. However, I can call testfunc just fine by creating the object within the function itself rather then as a class variable (noted in function test2)
Is there a way to get test() to work? id love to be able to call member functions from a class defined variable rather then in the function
class extclass
{
public function testfunc ()
{
return 1;
}
}
class testClass
{
private extclassObj;
public function __construct()
{
$extclassObj = new extclass;
}
function test ()
{
// fatal error calling member func on non obj
print $this->extclassObj->testfunc();
}
function test2 ()
{
//works fine
$extclassObj = new extclass;
print $extclassObj->testfunc();
}
}