Bright Hub
 
Matthew Casperson's Hubfolio

Creating your first PHP application with HAXE

Article by Matthew Casperson (229,259 pts )
Published on Nov 10, 2009

This tutorial shows you how to create a simple PHP application using HAXE and FlashDevelop.

Introduction

DOWNLOAD THE SOURCE CODE

Haxe is somewhat unique amongst programming languages. Typically when you write an application it is either compiled to a native executable, or compiled at run time to a virtual machine like Java, DotNet or PHP. Haxe is different. A program written in Haxe is instead compiled into source code for a target language like JavaScript, PHP, Flash, Neko or C++. This means that this one language can be run in a web page, on a web server or as a native executable.

So why would you bother with yet another programming language? As an example, using the Haxe language exclusively you can compile a PHP application to run on your server, compile some JavaScript to be run on the client web browser, and even compile a Flash applet to embed in the web page. This combination of PHP, JavaScript and Flash is not uncommon, and would normally require code written in 3 different languages, probably with 3 different IDEs. With Haxe you have one language and one IDE for all three technologies.

Depending on your existing programming experience, you may even find the Haxe language preferable. The code is similar to most of the other "C" style languages out there like C++, Java, C# and ActionScript.

In this tutorial we will create a simple PHP application use Haxe.

Step 1 - FlashDevelop

FlashDevelop is a free and very capable IDE, which you can download from here.

Step 2 - HAXE

You will also need a copy of Haxe, which you can download from here.

Step 3 - Create a new project.

Create a new FlashDevelop project by clicking Project->New Project...

HAXE PHP Screenshot

Create a new Haxe PHP project.

HAXE PHP Screenshot

Step 3 - Write some code

FlashDevelop will create an initial class called Main for you. Rewrite the class with the code below.

class Main

{

static function main()

{

php.Lib.print('Hello World!');

}

}

Step 4 - Build the project

Click the Build Project button in the toolbar. This will compile the code into the PHP files that your web server will use.

It is worth using Haxe just for the ability to compile the code. In languages like PHP and JavaScript especially, being able to pick up syntax errors at compile time saves a lot of time.

HAXE PHP Screenshot

Step 5 - Open the application

Include the bin folder created in the FlashDevelop project folder in your web servers path, and point a browser to the index.php file.

HAXE PHP Screenshot

Final Words

Haxe is a free and powerful technology that blurs the lines between a lot of popular web technologies like JavaScript, PHP and Flash. There is also quite a large collection of community Haxe libraries to help get you started, which you can find here.

Return to the Tutorial Index

Search More About:

 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape