FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to create an instance from a class name
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to create an instance from a class name [message #177810 is a reply to message #177809] Sun, 22 April 2012 02:23 Go to previous messageGo to previous message
Ross McKay is currently offline  Ross McKay
Messages: 14
Registered: January 2011
Karma:
Junior Member
On Sat, 21 Apr 2012 20:53:58 -0430, Leonardo Azpurua wrote:

> I am working on a class to generate a report from specs contained in a user
> defined file.
> [...]
> I recall having read somewhere an example of PHP instantiatiting an object
> from a class name, [...]

$className = 'ExampleClass';
$instance = new $className;

Can be quite handy in Singletons, e.g.

$className = __CLASS__;
$instance = new $className;
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session question
Next Topic: Open Source Software Links
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 02:20:29 GMT 2024

Total time taken to generate the page: 0.05892 seconds