[UPHPU] subsituting variable into new object command

Josh Jeppson uphpu at josh.jeppsons.org
Fri Jun 30 15:30:40 MDT 2006


On 6/30/06, jtaber <jtaber at johntaber.net> wrote:
>
> I'm writing a test module (which I'll show at next hacker mtg (thurs
> 6th) but I need to subsitute object names into a command to instantiate
> new objects ie:
>
> public function test1($objname='test') {
>   $obj = new $objname;  // this doesn't work
>   compare($obj->size, ......)
> }
>
> how can I subsitute into the new command ?  thks.
>
>
I think you're only missing the parens following the object name. Like so:
   $obj = new $objname();

I make use of code like that myself.  However, I don't know if it works on
PHP4. I do know 5.0.x and 5.1.x work beautifully.

- Josh


More information about the UPHPU mailing list