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.