Instantiating object by arbitrary name in string

    Date: 12/23/06 (PHP Community)    Keywords: no keywords

    How can I instantiate an object whose name I learn at runtime? What I mean is something like $view = new $viewName, where $viewName is a string representing the name of the object I wish to instantiate. One way I can think of is call_user_func(array($viewName, 'staticFactoryMethod')), but I suspect there might be a better way.

    This is for an application to which operators may add new interface rendering code, as a class implementing a specific interface, and then cause any page in application to be rendered by the new view plugin by including a string in the request URI corresponding to the name of the class to be instantiated. So, basically, a sort of dynamic plug-in system.

    Source: http://community.livejournal.com/php/524832.html

« Writing a SOAP server || Nested Loops?? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home