How to write closures in PHP

Here is an example of how you can create a closure in PHP, meaning, a variable is bound in a function.
In the example, $test->message is not defined inside the function returned by returns_function, and doesn't need to be declared in the scope of execution, it will print "hello" wherever you call $closure(), despite changing $test->message.

<?php

class Foo {  
    public $message = 'hello';

    function returns_function() {
        $message = $this->message;
        return function () use ($message) {
            var_dump($message);
        };
    }
}

$test = new Foo();
$closure = $test->returns_function();
$closure();
// "hello"
$test->message = "bye!";
$closure();
// "hello"

?>