Bug #68792 [Opn->Dup]: Can't declare closure using $this within static method (context)
| From: | requinix@php.net | Date: | Sat, 10 Jan 2015 23:00:12 +0000 |
| Subject: | Bug #68792 [Opn->Dup]: Can't declare closure using $this within static method (context) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189874@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68792&edit=1
ID: 68792
Updated by: requinix@php.net
Reported by: llmll at gmx dot de
Summary: Can't declare closure using $this within static
method (context)
-Status: Open
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: any
PHP Version: 5.5.20
Block user comment: N
Private report: N
New Comment:
You missed out on a warning
Warning: Cannot bind an instance to a static closure in...
making this a duplicate of bug #64761.
Previous Comments:
------------------------------------------------------------------------
[2015-01-10 17:43:13] llmll at gmx dot de
Description:
------------
The problem arises, when you try to declare a Closure (anonymous function) from within a static
method. The compiler breaks on the $this keyword which must not occur in a static method. However,
$this is only used in the closure body and should be ignored, therfore.
Test script:
---------------
class Test {
public static function start() {
$closure = function() {
echo $this->foo;
};
$object = new \StdClass;
$object->foo = "Hello World";
$closure->bindTo($object)->__invoke();
}
}
Test::start();
Expected result:
----------------
should echo "Hello World"
Actual result:
--------------
Fatal error: Using $this when not in object context
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68792&edit=1