Doc #72662 [Opn]: Anonymous function example 5 relies on PHP 7 syntax
| From: | requinix@php.net | Date: | Sun, 24 Jul 2016 05:49:06 +0000 |
| Subject: | Doc #72662 [Opn]: Anonymous function example 5 relies on PHP 7 syntax | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13747@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72662&edit=1
ID: 72662
Updated by: requinix@php.net
Reported by: playit2thelimit at gmail dot com
-Summary: Parse error: syntax error, unexpected '(' in C:\
....
+Summary: Anonymous function example 5 relies on PHP 7 syntax
Status: Open
Type: Documentation Problem
-Package: Documentation problem
+Package: Class/Object related
Operating System: Windows 7
PHP Version: 5.6.24
Block user comment: N
Private report: N
New Comment:
http://php.net/manual/en/functions.anonymous.php#example-203
Yeah, that (function{})() syntax requires PHP 7.
I'm not sure it's the best example, either. The docs are trying to show that $this is
available inside the function because the function was defined within the class, but in the example
it's both defined *and called from* within the class.
I think code like <https://3v4l.org/qVEF1> demonstrates
the concept better.
Previous Comments:
------------------------------------------------------------------------
[2016-07-23 23:35:36] playit2thelimit at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/functions.anonymous
---
Trying to understand example #5, but it does not compile.
Thanks!
- Chris
Test script:
---------------
<?php
class Test
{
public function testing()
{
(function() {
var_dump($this);
})();
}
}
(new Test)->testing(); // as of PHP 5.4
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72662&edit=1