Placing a factory inside an abstract class (use of 'self')
Posted: Thu Jun 21, 2007 9:58 am
This is driving me nuts. I understand the problem, but is there a workaround before PHP6 introduces the 'static' keyword to do what I want?
This give an error that I cannot instantiate the abstract class 'ORM'... fair enough, but I actually want to instantiate 'User', using a static method in the abstract class
Any hints?
Code: Select all
abstract class ORM {
// ... snip ...
public static function getInstance()
{
return new self(); //I've also tried __CLASS__ to no avail!!
}
public static function retrieveById($id)
{
$self = self::getInstance();
$self->doSomeMagicWith($id);
return $self;
}
}
class User extends ORM {
// ... snip ...
}
$user = User::retrieveById(112); //Get user #112