PHP4Mono

the Mono PHP Compiler

 

What is PHP4Mono?

PHP4Mono is a compiler that enables Mono to run PHP code. It translates PHP scripts to Common Intermediate Language (CIL). Like that PHP scripts can be executed as console applications on Mono.
You can even access other .NET assemblies and e.g. build Graphical User Interfaces directly from within a PHP script using the Gnome libraries.

Download

PHP4Mono is licensed under the GNU General Public License.
You can get binaries and source from the SourceForge Download Page.
Please note that PHP4Mono is still in development. You are welcome to report any issues in the SourceForge Bugs Page.

Requirements

The only requirement is Mono in version 1.1.8.3 or higher. No installation is necessary; just make sure the files mPHP.exe and mPHPRuntime.dll are located in the same directory after downloading. To ensure comfortable usage of the Mono PHP Compiler it is useful to ensure your path contains the Mono binaries directory.

Usage

To compile a PHP script, go to the directory where mPHP.exe is located. Then execute

mono mPHP.exe [<options>] <source file>

whereas <options> may be any of

-out:<file> Specifies output file
-target:<kind> Specifies the target (short: -t:)
<kind> is one of: exe, library
-reference:<file list> References the specified assembly (short: -r:)
Files in <file list> separated by , or ;
-nowarn Disables warnings
Displays this usage message (short: -?)

Examples

The binaries distribution of the Mono PHP Compiler includes a couple of examples. The simplest one demonstrates the compilation and execution of a PHP script on its own. Another one additionally demonstrates how a compiled PHP script can be used from a class written in another .NET language. Several other examples show how other .NET libraries can be accessed directly from within a PHP script. For a detailed description of these examples please refer to the file samples.pdf.

Features

The Mono PHP Compiler translates PHP scripts of version 5 to Common Intermediate Language (CIL) and like that enables them to be executable on Mono. Currently not all features of PHP are supported. See below for a more detailed overview.

PHP feature included not included
types boolean
integer
float/double
string
arrays
object
null
mixed
resource
number
callback
 
casting explicit
implicit
 
variables local
static
global
variable variables
predefined variables
superglobals
constants standard constants
magic constants
 
expressions all expressions except `...`
operators all operators except @
control structures if else elseif
while
do
for
foreach
switch
try catch
delcare
include/require
functions user defined functions variable functions
built-in functions
external modules
classes and objects inheritance
overloading
abstraction
interfaces
cloning
iterators
reflection

More

A summary of PHP4Mono including an example and facts about the compiler, PHP and Mono is available on this poster.
Detailled background information is available in this book which describes the compiler in more detail. If you would like to contribute to this project or to know more about the compiler's internals, this is a good point to start with.

Roadmap

After the basics are done with version 0.2, the next steps should increase usability. First, a basic library should be implemented containing standard functions available in PHP (for handling arrays, strings etc). Second, PHP extensions should be made accessible by the compiler. Like that any native extension can be used without the need of re-implementing it. Any developer who likes to contribute to the project is welcome and sould contact me.

Press (German)

Golem.de - PHP bändelt mit .Net an (2-24-2006)
derStandard.at - Aus PHP wird .Net (3-5-2006)
Heise - PHP-Compiler für Mono in neuer Version (3-8-2006)
LiSoG - Supported Project (3-17-2006)
idw - Neue Skriptsprache für Open-Source-Platform "Mono" (3-31-2006)

Acknowledgement

The Mono PHP Compiler originally was my final year project at the University of Augsburg in collaboration with the Linux Solutions Group. In 2005 it was sponsored by Google's Open Source Funding Summer of Code in contribution with the Mono Project. Special thanks to Bernhard Bauer, Thomas Uhl, Tom Schwaller, Miguel de Icaza and Chris di Bona for supporting this project.

Raphael Romeikat, April 3rd, 2006