php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62706 array_map documentation is missing info about "use" keyword
Submitted: 2012-07-31 17:51 UTC Modified: 2012-07-31 20:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: lists at box dot cz Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: Irrelevant OS: irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lists at box dot cz
New email:
PHP Version: OS:

 

 [2012-07-31 17:51 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-31 19:14 UTC] salathe@php.net
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
 [2012-07-31 19:14 UTC] salathe@php.net
-Status: Open +Status: Wont fix
 [2012-07-31 20:26 UTC] lists at box dot cz
I respectfully disagree, even if it doesn't get me anywhere.

The example #2 present on that page documents exactly the thing that "doesn't belong on the array_map() page".

Trouble is, example #2 is idiotic (half-assed multiply-by-two function) and a link to anonymous function (eh, "closures") documentation is nowhere to be found on the array_map() page.

To me that's confusing because I'd have to know about "functions.anonymous.php" to be able to find the whole truth.

Why not make it:
1) easier for people to find docs for anon functions;
2) clear that there's more to array_map() [as of 5.3.X].

By that I mean -- changing Ex#2 to something more meaningful *and* adding link to functions.anonymous.php.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Apr 25 00:01:27 2025 UTC