OO php: static and factory classes
Jeff Schroeder
jeff at zingstudios.com
Fri Aug 31 16:30:43 MDT 2007
> $objName = "Widgit";
> $objName::getWidgitStatic();
>
> Why does the bottom one not work?
Because $objName is a string variable. You can't apply a method to a
string.
You *may* be able to do this (I haven't tested it):
$$objName::getWidgetStatic();
The double-dollar means "interpret the string", which might evaluate
to "Widgit" and work.
This will definitely work:
eval($objName . "::getWidgetStatic();");
Here you're sticking the string into the eval() expression, so it gets
intepreted like you want.
HTH,
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20070831/42f4680f/attachment.bin
More information about the PLUG
mailing list