Page 1 of 1

Calling static object via variable?

Posted: Fri Sep 25, 2009 1:40 pm
by supergrover1981
Hi gang,

I'd like to be able to call a static object through a variable - I'm wondering how to do that. To give an example:

Code: Select all

function ($className) {
  $singleton = $className::getInstance();
}
Of course, this returns an "unexpected T_PAAMAYIM_NEKUDOTAYIM" error.

So if $className = 'exampleClass', how do I get PHP to read that line as 'className::getInstance()'?

Many thanks,
- JB

Re: Calling static object via variable?

Posted: Fri Sep 25, 2009 1:55 pm
by jackpf
I think you can do this in PHP 5.3.

Not sure about below.