Calling static object via variable?

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
supergrover1981
Forum Newbie
Posts: 11
Joined: Sun Nov 26, 2006 6:36 am

Calling static object via variable?

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Calling static object via variable?

Post by jackpf »

I think you can do this in PHP 5.3.

Not sure about below.
Post Reply