Connecting Tech Pros Worldwide Forums | Help | Site Map

smth like Class.forName() in PHP?

Sergei Riaguzov
Guest
 
Posts: n/a
#1: Jun 2 '08
Is there a way to create an instance of a class SomeClass in PHP having
a string "SomeClass"? The idea is to create instances on classes based
on dynamic information obtained from $_POST. Like

Java has a useful construct for that - Class.forName(). Is it possible
to do same in PHP? Like:

$obj = createClass($_POST['className'])

or smth?

Alexey Kulentsov
Guest
 
Posts: n/a
#2: Jun 2 '08

re: smth like Class.forName() in PHP?


Sergei Riaguzov wrote:
Quote:
Is there a way to create an instance of a class SomeClass in PHP having
a string "SomeClass"?
$className='SomeClass';

$var=new $className();
Closed Thread