Home | Downloads | Documentation | Plugins | Spinoff Projects | Mailing List

Spinoff Projects

PHT

We are delighted to announce the first actual spin-off from phc. Written by Daniel Barreiro, PHT embeds HTML/XML into PHP to ensure that the XML or HTML output by PHP scripts is well-formed and (although this has not yet been implemented) valid. Details and source can be found at http://www.satyam.com.ar/pht/.

Plumhead

Plumhead is written by Bernhard Schmalhofer and attempts to implement PHP on Parrot by taking the XML output from phc and transforming it (using XSLT) to the Parrot internal representation. See http://www.perlfoundation.org/parrot/index.cgi?plumhead for more information.

Suggestions

Below is a list of other projects that we'd love to see built. All of these tools are very difficult to implement starting from scratch. With phc as a base from which to work, the burden of developing any of these tools should be greatly reduced.

Refactoring Tool

According to www.refactoring.com, refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. A simple example of refactoring is renaming a variable name or a function name. More complex refactoring may involve finding repeated blocks of code inside a script and moving them to a function.

While simple refactorings can be coded directly in phc (see for example the Demo), a dedicated refactoring tool based on phc would make this process much easier for the end-user. It could even provide a graphical user interface offering common refactoring tasks, so that the programmer does not need to write any code at all to refactor their code.

We are planning to include type inference in phc at some point, which should increase the usefulness of phc for refactoring greatly (see What's in Store?).

See also Tutorial 2 for an example of a useful refactoring for PHP.

Style Checker

Software companies often have a series of “programming style guidelines” that dictate how classes, methods and variables should be named, if and where there are compulsory comments, etc. This is useful to make sure that code written by different programmers looks the same. This is also useful in open source projects, with lots of programmers working on the same codebase.

A style checker is a tool that knows about these guidelines and is able to check whether a particular program adheres to them. It is possible to write a style checker for a particular set of guidelines directly. However, a dedicated tool for style checking should be able to read in a set of guidelines (either in text form or using a GUI) and verify programs according to them.

Note that phc records line number and comments in the generated tree, so that they can be used in the verification process too.

Aspect Weaver

Aspect oriented programming is a relatively new programming paradigm. The standard example to explain what AOP does for you is the following. Suppose you have a script with a series of functions. Say you want to start and end every function with a call to some logging function:

<?php
   function some_function
   {
      log("some_function: begin");

      /* do whatever the function should do */

      log("some_function: end");
   }
?>

And say you want to do that in each and every function, for example for debugging purposes. It's a lot of work to do that manually for every function. And when you no longer need it, it is a lot of work to remove it again. This is what's known as a cross-cutting concern: something you need to implement (in this example, logging), that “cross-cuts“ (affects) a lot of code. With AOP, you can write this concern as a single “aspect”. You then run your program through an “aspect weaver”, which will insert the necessary code at the start and end of each function, thus saving you a lot of work.

For more information, check out AspectJ, an aspect weaver for Java (www.eclipse.org/aspectj), or read for example AspectJ in Action by Ramnivas Laddad. You can do some very slick things with aspect oriented programming :-)

phc would be a good foundation upon which to build an aspect weaver for PHP.

Script Obfuscator

Most PHP scripts are distributed in source form. But what if you don't want people to modify your code? Or what if you want to make your code as difficult to understand as possible, so that it becomes harder to analyse it for possible attacks? A script obfuscator takes a PHP script and outputs another PHP script that does the same thing, but is completely unreadable. There are a few obfuscators available for PHP, but a script obfuscator based on phc can make use of a lot of structural information about the script, opening new avenues for great obfuscation :-)

Script Optimizer

Similar to a script obfuscator, a script optimizer takes a PHP script and outputs another PHP script that does the same thing, but runs much faster. As a simple example, consider
<?php
   echo "Text $with variables.";
?>
This could be changed to
<?php
   echo 'Text ', $with, ' variables.';
?>
which should run faster. Many other optimizations are possible.

Pretty Printers

phc includes a standard pretty printer that outputs the AST (phc's internal representation of a script) into normal PHP, but it is rather limited. For example, it cannot be configured. Moreover, it can probably be improved in a number of places. For example, it really should deal better with brackets in expressions (at the moment, it simply copies the brackets from the user).

A pretty printer would take an AST and output it in some way. For example, it could output the AST to normal PHP code, but in a different layout style than the standard unparser does. But you could also think of other unparsers. For example, it might output to HTML or Latex, so that you can include PHP examples in HTML websites or in Latex documents.

Since version 0.1.6., the phc unparser is defined as a tree visitor, so it is possible to define new unparsers by inheriting from the PHP_unparser class, and redefining only those features that need to be improved.

Language Translation

Tools that translate PHP into other languages (for example, a PHP to ASP translator). Note that this is a much more difficult task than the other projects mentioned, and such a tool would benefit greatly from future additions to phc itself (which is, after all, a compiler).

Semantic Checker

Like a style checker, a semantic checker does not actually modify a PHP script, but checks it instead for “bugs”. For example, it could issue a warning in the following code
<?php
   $a = "some text " + $b; 
?>
(The + should probably have been a .). This project will also benefit from future releases of phc (see What's in Store?).

Make Yourself Known!

If you are interested in starting on any of these (or other) projects, and you need help, do not hesitate to send questions to the mailing list.

Also, if your tool has reached some level of usability, and you would like to see it listed on this website, please let us know. In fact, if your tool is real good, we could even integrate it into phc itself.

Either way, if you are building software based on phc, we would really love to know about it — so please keep us posted!

Donations

Finally, if you do write a tool based on phc, and you're making buckets of money, we'd appreciate a donation :-) Contact us at donations@phpcompiler.org.
$LastChangedDate: 2006-11-30 15:34:04 +0000 (Thu, 30 Nov 2006) $. Contents © the authors.