Thats a pretty crappy example to put on the homepage: 13 lines of Ruby compiled into 67 lines of PHP. You could write some PHP more or less identical to the Ruby in the same original 13 lines.
class Greeter {
public static function greet($text) {
echo $text;
}
}
Greeter::greet("Hello, World!\n"); class Greeter {
public function __construct($fn) {
$this->greeting = $fn();
}
public function greet() {
echo $this->greeting;
}
}
$greeter = new Greeter(function() {
return "Hello, World!";
});
$greeter->greet();
That code will only work in PHP 5.3. If you want anonymous functions in lower versions, you're going to have to use create_function(). If you want closures, you may as well forget about doing it nicely.There's a reason the Fructose generated PHP isn't very pretty. The Fructose generated code will run on any version of PHP that's at least 5.0.