[Tutor] Creating an object with a string

Alan Gauld alan.gauld at blueyonder.co.uk
Mon May 24 13:01:59 EDT 2004


> I am parsing an XML file, and based on certain tags, i want to
create
> certain objects.

Sounds exactly like SAX to me.
I assume you are using the standard parsers and not trying to
craft something by habd based on regexs or somesuch?

SAX is an event based parser so you simply create a function
that you associate with each XML tag you are interested in.
When the parser hits that tag type it calls your function.

> <?php
> $object = "ClassToCreate";
>
> $newObject = new $object();

You could do something like that with eval() but using eval()
and exec() should really be a last resort, better to use the
power of the tools IMHO.

Alan G.




More information about the Tutor mailing list