Re: 5.4 beta
| From: | Gustavo Lopes | Date: | Sat, 08 Oct 2011 17:22:18 +0000 |
| Subject: | Re: 5.4 beta | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55755@lists.php.net to get a copy of this message | ||
On Sat, 08 Oct 2011 11:02:57 +0100, Frédéric Hardy <frederic.hardy@mageekbox.net> wrote:
Hello !You can take a look at the tests. For instance, this patch has many: http://nebm.ist.utl.pt/~glopes/misc/closures_scope.patch For more, you can look at the SVN tree (Zend/tests/closure_*). In any case, here is a very simple example: <?php class A {I don't think so, but if I had to summarize the innovations in 5.4, this would be it: - Closures can now have an associated scope - Closures can now have a bound object - Closures can now be either static or non-static - Closures defined in a place with an active scope are scoped accordingly - Closures defined inside an instance method (or bound closure) have a bound object (namely $this) - Closures are static if defined within a static method or with the static keyword (static function() { ... })Is it possible to have sample code about these ? They will be very interesting to understand the RFC correctly and write documentation or tutorial. For example, i was tryed to use $this in a closure with PHP 5.B beta without any success :/, so if using $this in a closure is possible, i would like to know how to do it..
private $foo = "bar";
function foo() { return function () { return $this->foo; }; }
}
$a = new A;
$c = $a->foo();
echo $c(); //echos "bar"
--
Gustavo Lopes