Doc #71348 [Asn->Csd]: Static anonymous functions are not documented
| From: | tpunt@php.net | Date: | Sun, 22 May 2016 20:06:29 +0000 |
| Subject: | Doc #71348 [Asn->Csd]: Static anonymous functions are not documented | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13463@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71348&edit=1
ID: 71348
Updated by: tpunt@php.net
Reported by: korikulum at net dot hr
Summary: Static anonymous functions are not documented
-Status: Assigned
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Assigned To: tpunt
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2016-05-22 19:45:41] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&revision=339215
Log: Resolve doc bug #71348
------------------------------------------------------------------------
[2016-04-20 16:26:14] nikic@php.net
Related To: Bug #61999
------------------------------------------------------------------------
[2016-01-12 10:54:19] korikulum at net dot hr
Description:
------------
---
From manual page: http://www.php.net/functions.anonymous
---
Since PHP 5.4 anonymous function can be declared statically
(https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#anonymous-function-creation).
When an anonymous function is declared statically, it prevents auto-binding to the instance it is
in. Also, it can not be bound using the bind, bindTo & call functions.
Test script:
---------------
class Foo
{
public function bar()
{
return static function () {
var_dump($this);
};
}
public function baz()
{
return function () {
var_dump($this);
};
}
}
$foo = new Foo();
$bar = $foo->bar();
$bar();
// Notice: Undefined variable: this
// NULL
$baz = $foo->baz();
$baz();
// object(Foo)#1 (0) {
// }
Closure::bind($bar, new StdClass());
$bar->bindTo(new StdClass());
$bar->call(new StdClass());
// Warning: Cannot bind an instance to a static closure
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71348&edit=1