doc/php/code_generator
Differences between version EMPTY and #1775
0a1,24 > ====== Introduction ====== > > Starting with the new major release of Haxe (2.0) a new target has been added to the compiler: ''PHP''. This permits to create your applications in Haxe and deploying them in the super-diffused PHP environment. > The generated code fully supports the Haxe syntax with no exceptions known. You can take a look [[/ref|here]] to see what Haxe is capable of. If you are a PHP developer you will be happy to know that now you can easily create local functions, anonymous objects with functions (not just keyed arrays), use packages (well the PHP versione 5.3 supports namespaces natively but we will have to wait quite a lot before having them available on shared hostings), pass function reference with ease and so on ... > The PHP code generated by Haxe is compatible with PHP 5.1.6 or later (probably any 5.1.x release work but it has not been tested). > > ====== Generated Files ====== > > To generate PHP from the Haxe compiler you will need to set the ''-php'' switch. The switch accepts a single parameter ''dir'' that is the directory where the generated files will be put. > > The following command creates PHP code in the ''www'' directory, assuming that you have a class ''Index''. > > <code> > haxe Index -php www > </code> > > In the ''www'' folder you will find a directory ''lib''. This directory contains the generated PHP files. A file is generated for every type defined in the application; the file is the same of the type with appended the type identifier (''.class'', ''.enum'' or ''.interface'') and the standard ''.php'' extension. For every package, and sub-package, is generated a folder. > Even if your ''Index'' class is very simple (let's say the classic "Hello world!" application as explained in the [[/doc/start/php|start tutorial]]) you will find that the generated files are quite enough. You can open some of them to see the aspect of the generated files. You will probably find that the generated code is quite readable. If you open a file inside a sub-folder (ei: haxe.Log) you will see that the class ''Log'' has been generated as the PHP class ''haxe_Log''. The package name is always prefixed to the type name to avoid conflicts. > > If you add the ''-main'' switch to the above command-line, a new file ''index.php'' will be generated in the ''www'' folder. This file just contains a reference (''require_once'') to the php.Boot class that performs some startup operations and to the static method ''main'' in the Index class. You can change the name of ''index.php'' adding the switch ''--php-front default.php'' where ''default.php'' is the desired new name. > > Digging into the files generated into the ''lib'' directory, you will find that there are no "require" or "require_once" statements. The generated code uses the autoloading feature of the PHP SPL to load the required files. On each execution, the boot process (contained in the ''php.Boot'' class) will scan the entire ''lib'' content in search of types and will add them to an hashtable that will be used by the autoloading function. To avoid the scan process you can create an empty folder ''cache'' in the ''www'' folder. This folder must be writeable by the PHP process. On the next script access a file ''haxe_autoload.php'' is created in the ''cache'' folder. From now on the ''lib'' will not be scanned again unless you manually erase the cache file. To avoid cases of "error: Class not found" it is better to avoid the cache mechanism until the application is moved to its production environment. > > A third folder ''res'' is generated by the compiler if one or more [[/doc/advanced/resources|resources]] have been added to the compile process. \ No newline at end of file
Ver | Date | Lg | User | Action |
---|---|---|---|---|
#5805 | 2009-04-18 09:49:25 | es | Perberos | View | Diff |
#5804 | 2009-04-18 09:29:55 | es | Perberos | View | Diff |
#5803 | 2009-04-18 09:21:00 | es | Perberos | View | Diff |
#5802 | 2009-04-18 09:13:05 | es | Perberos | View | Diff |
#5801 | 2009-04-18 09:13:05 | es | Perberos | Set title to Haxe/PHP: generador de código |
#4714 | 2008-10-22 12:22:31 | en | ponticelli | Changed title from Haxe/PHP code generator to Haxe/PHP: code generator |
#4667 | 2008-10-08 14:23:57 | fr | djleop | Set title to Haxe/Générateur de code PHP |
#4666 | 2008-10-08 14:22:54 | fr | djleop | View | Diff |
#1775 | 2008-07-26 21:56:37 | en | ponticelli | View | Diff |
#1774 | 2008-07-26 21:56:37 | en | ponticelli | Set title to Haxe/PHP code generator |
Previous | Next