views:

57

answers:

2

Hi,

I'm in PHP and I must access a Static method of an object which name must change.

   private $controlleur = null;
   private static $instance = null;

   private function __construct() {
     $nomControlleur = "Controlleurs\_" . Session::singleton()->controlleur;
     $this->controlleur = $nomControlleur::singleton();
   }

This preceding code is giving me " Syntax error unexpected :: ".
I've also tried writing {$nomControlleur}::singleton(); but it's giving me even more errors, thanks a lot for your help.

Balls of steel

A: 

What about

$staticCall = $nonController."::singleton()";
$staticCall();

?

timdev
Thanks, nearly that, but I have find it with your comment. Just pull of the () in singleton() beacause when you call it it gives singleton()();
Balls-of-steel
+2  A: 

Use:

$this->controlleur = call_user_func(array($nomControlleur, 'singleton'));

or (5.2.3+ only)

$this->controlleur = call_user_func($nomControlleur . '::singleton');
chaos