[phc-general] resolving dynamic includes

Paul Biggar paul.biggar at gmail.com
Mon Jul 2 22:22:25 CEST 2007


Hi Gary,

On 7/2/07, Gary Wassermann <wassermann at ucdavis.edu> wrote:
> I understand that phc will not be able to resolve dynamic includes in PHP
> files.

Sadly, no. After a bit of data-flow, though, we may be able to get a
decent portion. Future work :)

> However, suppose I use phc to parse in a PHP file that has a
> dynamic include, and after parsing it in completely, I am able to supply
> the name of the file to be included.  Is there a natural way in phc to
> support this?  In other words, is there a way to invoke the parser from an
> AST node and have the resulting AST be what it would have been if the
> include could have been resolved statically?  Thanks for your help.

That seems like quite a decent idea. Have a look in
src/process_ast/Process_includes.cpp. A simple call to parse() will
get you an AST, given a filename. Your best bet may be to add a
AST_transform plugin which searches for includes or requires, and asks
the user for the filename in whatever way you feel is useful. Then
call parse on the filename, and you'll have the AST. Integrating the
new AST is a simple case of calling in->push_back.

Includes is is very high on my list of priorities, as we try to get
ready for the next release. Currently, it's disabled, but it shouldn't
be too hard to fix, and I might try to get it done for you in the next
few days if I get a chance.

Edsko redid the tutorials recently, and one of his examples was
handling includes. Look at
http://phc.googlecode.com/svn/trunk/doc/manual/treetutorial6.sgml for
the details. (If you check out the source you'll be able to build this
so that its much more readable).


I hope I've provided enough information here, but I'm a bit rushed
right now. Let me know if there's anything I've glossed over too much.

Thanks
Paul

-- 
Paul Biggar
paul.biggar at gmail.com


More information about the phc-general mailing list