5 ms·
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 Rub
by stanmancan 16y ago
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.
- ctide 16y agoI imagine the example is pretty indicative of how it works. Better to have a crappy example than no example at all.
- fosk 16y agoActually most of the code initializes Fructose, in PHP I can write the same code like (6 lines, 7 including blank line): class Greeter { public static function greet($text) { echo $text; } } Greeter::greet("Hello, World!\n");
- electrum 16y agoThat code isn't the same as the original. The instance variable is being initialized via a block -- your function needs to accept a callback.
- charliesome 16y agoThis would be the PHP that'd do the same thing: 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.