You have encountered one of PHPs more annoying limitations. The person::create method does not know that it was called using student::create.
One solution is to add a create method to each of the derived classes and then pass a parameter to the parent.
class student extends person
{
static function create()
{
parent::create('student');
}
This can get old real fast especially if you have more than one static function that needs to be mapped.
The only real solution is to use a factory object to create your stuff. maybe something like:
class PersonFactory
{
$itemClassName = NULL;
function create()
{
return new $this->$itemClassName();
}
}
class StudentFactory extends PersonFactory
{
$itemClassName = 'Student';
}
$studentFactory = new StudentFactory();
$student = $studentFactory->create();
$factory = new PersonFactory();
$student = $factory->createStudent();
May seem like a bit of a pain but, in general, using objects is easier than using statics.