Doc #62706 [Wfx]: array_map documentation is missing info about "use" keyword

From: Date: Tue, 31 Jul 2012 20:26:31 +0000
Subject: Doc #62706 [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-8661@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
 User updated by:    lists at box dot cz
 Reported by:        lists at box dot cz
 Summary:            array_map documentation is missing info about "use"
                     keyword
 Status:             Wont fix
 Type:               Documentation Problem
 Package:            Documentation problem
 Operating System:   irrelevant
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-07-31 19:14:37] 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 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


Thread (3 messages)

« previous php.doc.bugs (#8661) next »