Page 1 of 1

Creating Object Names on the Fly

Posted: Fri May 28, 2010 2:55 pm
by Jim1
Hi all,

I'm having some problems creating an object name on the fly. I'd assume it was the following to generate 'new TestObject()':

Code: Select all

$objectname = "Test";

$object = new {$objectname}Object()
But that doesn't work. What's the correct syntax to do this?

Thanks for any replies,

Jim.

Re: Creating Object Names on the Fly

Posted: Fri May 28, 2010 3:01 pm
by Eran
The entire name needs to be a string.

Code: Select all

$objectname = "TestObject";
$object = new $objectname;

Re: Creating Object Names on the Fly

Posted: Fri May 28, 2010 4:41 pm
by Jim1
Thanks, that worked great!