When I run the following code I get B as expected:
class A {
public function __construct($file){}
}
class B extends A {
public function __construct() {
parent::__construct('test.flv');
}
}
$b = new B();
print get_class($b);
However, consider a slightly modified version of this code (here ffmpeg_movie class is a part of http://ffmpeg-php.sourceforge.net library):
class B extends ffmpeg_movie {
public function __construct() {
parent::__construct('test.flv');
}
}
$b = new B();
print get_class($b);
It returns ffmpeg_movie instead of B. Furthermore, it turns out that methods defined in B class aren’t accessible when using $b object:
class B extends ffmpeg_movie {
public function __construct() {
parent::__construct('test.flv');
}
public function test() {
print 'ok';
}
}
$b = new B();
$b->test();
Fatal error: Call to undefined method ffmpeg_movie::test() in .../test.php on line 13
What exactly is going on here and is there a workaround?
I didn’t find out what was the origin of the problem. I managed to solve it though by not extending ffmpeg_movie class directly and instead using
__call,__getand__setPHP magic methods to mimic inheritance.