php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61999 Static lambdas not documented
Submitted: 2012-05-10 18:55 UTC Modified: 2016-05-22 20:06 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kenaniah at gmail dot com Assigned: tpunt (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.3 OS: Any
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
12 - 5 = ?
Subscribe to this entry?

 
 [2012-05-10 18:55 UTC] kenaniah at gmail dot com
Description:
------------
Neither http://php.net/manual/en/class.closure.php nor 
http://www.php.net/manual/en/functions.anonymous.php mention that anonymous 
functions / lambdas bind the object they are defined in to $this, and that the 
automatic binding functionality can be avoided by declaring the lambda as 
static:

<?php
$lambda = static function() { ... }
?>

There should probably be a warning about generating lambdas in object contexts 
as it silently binds a reference to the defining object, which could cause all 
sorts headaches when attempting to cause the destruction of an object.

Defining a static lambda like the code sample above prevents the lambda from 
binding to its defining object. Please patch the documentation accordingly.

Thanks!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-20 16:26 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-04-20 16:26 UTC] nikic@php.net
Duplicate of (newer) bug #71348.
 [2016-05-22 19:48 UTC] tpunt@php.net
-Assigned To: +Assigned To: tpunt
 [2016-05-22 20:06 UTC] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339217
Log: Resolve doc by #61999
 [2016-05-22 20:06 UTC] tpunt@php.net
-Status: Duplicate +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC