Doc #62706 [Opn->Wfx]: array_map documentation is missing info about "use" keyword
| From: | salathe@php.net | Date: | Tue, 31 Jul 2012 19:14:37 +0000 |
| Subject: | Doc #62706 [Opn->Wfx]: array_map documentation is missing info about "use" keyword | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8660@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62706&edit=1
ID: 62706
Updated by: salathe@php.net
Reported by: lists at box dot cz
Summary: array_map documentation is missing info about "use"
keyword
-Status: Open
+Status: Wont fix
Type: Documentation Problem
Package: Documentation problem
Operating System: irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Documenting the details of wrapping variables within closures, or indeed
mentioning it in passing, does not belong on the array_map() page. That is what
the dedicated anonymous functions / closures page [1] is for.
[1] http://php.net/manual/en/functions.anonymous.php
Previous Comments:
------------------------------------------------------------------------
[2012-07-31 17:51:21] lists at box dot cz
Description:
------------
---
From manual page: http://www.php.net/function.array-map#refsect1-function.array-map-examples
---
When first looking at array_map() I thought it's a fantastically useless function (compared to
other languages, Ruby being notable example).
The reason was perceived inability to access parent scope.
Only when discussing the matter with a more skilled PHP dev I was told there is a way to access
parent scope.
Therefore the documentation should include mention of the construct:
<?php
$vars = array('a' => 'one', 'b' => 'two',
'c' => 'three');
$a = array('a', 'b', 'c');
$f = function($x) use ($vars) { return $vars[$x]; };
print_r(array_map($f, $a));
?>
to make it abundantly clear it is, indeed, possible.
Expected result:
----------------
To find the info in that docs section.
Actual result:
--------------
No mention of "use" within official text.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62706&edit=1