PDA

View Full Version : 'new' operator


nerhael
05-20-2003, 06:02 PM
Let's say I have an object called 'MyObject', and I have a string holding the value "MyObject", is there a way that I can instantiate an instance of 'MyObject' using that string value?

Basically, I'm going to have a string value that will be the name of an object, and want to instantiate whatever object it refers to.

Pete.

mordred
05-20-2003, 09:48 PM
That's quite elegantly made in PHP, you just use the concept of variable variables combined with the new operator/class instantiation.


class Foo
{
var $prop = "bar";

function Foo() {

}
}

$anything = "Foo";
$myObj =& new $anything();

var_dump($myObj);