Because BaseFoo
doesn't extend MyClass1
, it isn't called a base class. This means that you indeed can't use parent
. You need to have an object on which you can call the method.
Depending on what you want, you may need to create an object (or pass one) of class BaseFoo
in MyClass1
(local or as a member) or you may make BaseFoo::check()
static:
class BaseFoo(){
static function check(){
// Note: you can only access static members here
// Calling non-static methods statically generates an E_STRICT level warning.
}
function f1($o){
$c = new MyClass1();
return $c->f1($o);
}
}
Most likely, however, that's not what you actually want to do. You should ask the question "Who owns what?". Here, BaseFoo
owns the MyClass1
object. So you probably want this:
class BaseFoo(){
function check(){
//do somme stuff
}
function f1($o){
$c = new MyClass1();
check();
return $c->f1($o);
}
}
And:
MyClass1(){
function f1(){
// Don't check here, the creator should check
// do other stuff
}
}
You may need to check for different things both in MyClass1
and in BaseFoo
though, and you would have 2 separate check
methods for that.