Variable class name, static method

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!

Moderator: General Moderators

Post Reply
ignuss
Forum Newbie
Posts: 1
Joined: Mon Jul 20, 2009 8:32 pm

Variable class name, static method

Post by ignuss »

I apologize if the title is not exactly accurate, but my head just goes nuts when I try to think how would I name what I want to do, as a programmer, its always easier with code:

Code: Select all

 
$dataMapper = self::DATAMAPPER_PREFIX . "_something";
$this->setMapper($dataMapper::getInstance()); //this line gives error
 
The classes I want to load are all singleton. I know it may be easier to implement something like a Registry but I want to do it this way (plus, I dont have that many different class names, so maybe it's not worth it)

Thanks for the help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variable class name, static method

Post by requinix »

I don't think there's a way of doing it with just variable-variable syntax, so

Code: Select all

$this->setMapper(call_user_func(self::DATAMAPPER_PREFIX . "_something::getInstance"));
Post Reply