PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
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?
To instantiate User from within ORM will give an infinite loop. And even if it would work, you would overwrite the "outside" object with the "inner" one.
That's a nice solution thanks Exactly the clean workaround I was thinking of
~djot, I've not got the foggiest what you're talking about The method was a static method you you're in object context there... it would have worked fine if it created a "User" object rather than a ORM object.