Hi everyone,
Quite a difficult problem here. I need help confirming if this is a bug in PHP5 or not, as I think the following code produces an incorrect result. However, I am open to education if I have assumed that this result is false.
Basically, I have a base class which contains a static method. The static method should return an instance of the class. If I use the base class to extend from, I would assume that the static method would return an instance of the derived class, NOT an instance of the base class:
<?php
class BaseClass {
static public function fetch() {
return new self;
}
}
class ConcreteClass extends BaseClass {
private $title;
public function setTitle( $newTitle ) {
$this->title = $newTitle;
}
}
$c = ConcreteClass::fetch();
var_dump($c);
$c->setTitle('My Title');
?>
This results in $c containing an instance of BaseClass, not, as I assume, an instance of ConcreteClass.
Am I wrong here or is this a bug?
Cheers!
Jalf