Saturday, June 19, 2010

OO Hello World - Phalanger



Phalanger version of the OO Hello World is here!
Phalanger is a PHP compiler targeting the .NET CLR. It allows you to create any type of .net applications, not only Web apps, but also console, windows forms, and libraries using the PHP language and libraries.

If you are new to the PHP programming language you can go to the Phalanger Info section.


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples. 

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.
<?
class Greet 
{
    private $name;
    function __construct($name)
    {    
        $this->name = ucwords($name);
    }
    function Salute()
    {
        echo "Hello {$this->name}!";        
    }
}

// Greet the world!
class Program
{
    static function Main()
    {                    
        $g = new Greet("world");
        $g->Salute();
    }
}
?>

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
<?php
import namespace System;
namespace GreetProgram
{   
    [Export] 
    class Greet 
    {
        private $name;
        public function __construct($name)
        {
            $this->name = ucwords($name);
        }
        public function Salute()
        {
            echo "Hello {$this->name}!";
        }
    }

    // Greet the world!
    class Program
    {
        public static function Main()
        {                    
         $g = new GreetProgram:::Greet("world");
         $g->Salute();         
        }
    }
}
?>

The Program Output:










Phalanger Info:

“Phalanger is a project which was started at Charles University in Prague and was supported by Microsoft. It compiles source code written in the PHP scripting language into CIL byte-code. It handles the beginning of a compiling process which is completed by the JIT compiler component of the .NET Framework. It does not address native code generation nor optimization. Its purpose is to compile PHP scripts into .NET assemblies, logical units containing CIL code and meta-data. Phalanger can run real-world PHP applications, many with minor to no modifications.” Taken from: (http://en.wikipedia.org/wiki/Phalanger_(compiler))

Appeared:
2003
Current Version:
Developed by:
Tomas Matousek, Ladislav Prosek, Vaclav Novak, Pavel Novak, Jan Benda, and Martin Maly
Creator:
Tomas Matousek, Ladislav Prosek
Influenced by:
PHP (Rasmus Lerdorf)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
CLR
Latest Framework Target:
2.0
Mono Target:
Yes
Allows Unmanaged Code:
No
Source Code Extension:
“.php”
Keywords:
92
Case Sensitive:
No
Free Version Available:
Yes
Open Source:
Yes
Standard:
No
Latest IDE Support:
Visual Studio 2008 (pro, shell)
Language Reference:
Extra Info:


1 comment: