Doc #71739 [NEW]: Parameter passing methods should be clearer
| From: | athalas at gmail dot com | Date: | Tue, 08 Mar 2016 11:16:08 +0000 |
| Subject: | Doc #71739 [NEW]: Parameter passing methods should be clearer | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-13237@lists.php.net to get a copy of this message | ||
From: athalas at gmail dot com
Operating system: Irrelevant
PHP version: 5.5.33
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Parameter passing methods should be clearer
Description:
------------
---
From manual page: http://www.php.net/function.array-filter
---
The trouble I found with this page is that a common requirement for the
filter is to pass extra information for filtering, further than the
array elements itself (for example, an external object or a flag that
controls the filtering).
I think that the closure method (PHP 5.3+) for passing parameters to the
callback function should be prioritized and shown very early in the
function docs (in the first screen should be ideal), as is a PHP
conformant and very nice/easy method to do it.
I always forget it and I always need a quick google search to find the
snippet, that I think (and suggest) it should be in the main page, not
even within comments, but as one of the usage examples of the
array_filter() function.
Thanks for your consideration.
Regards,
David
Test script:
---------------
<?php
$obj2 = new stdClass();
$obj2->color = 'red';
$external_flag1 = 'green';
$data = array( 'green', 'red', 'blue' );
$filtered_data = array_filter($data, function($color) use
($external_flag1, $obj2) {
return (($color == $obj2->color) || ($color == $external_flag1));
});
// will act depending on the color of $obj2 object and external_flag1
value
var_dump($filtered_data);
/*
returns:
// blue is removed as the array_filter result for that item is false
array(2) { [0]=> string(5) "green" [1]=> string(3) "red" }
*/
Expected result:
----------------
Looking at the first page of the array_filter() function documentation
should expose the closure example (and/or maybe other methods) for a
common method to pass external parameters into the callback for the
filtering process.
Actual result:
--------------
Actually, you need to dig into the user comments (way down) to find an
example, and you must remember yourself that this option exists at all.
It should be more explicit, as it forces always to do extra search and
find other docs to solve it.
--
Edit bug report at https://bugs.php.net/bug.php?id=71739&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71739&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71739&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71739&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71739&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71739&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71739&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71739&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71739&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71739&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71739&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71739&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71739&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71739&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71739&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71739&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71739&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71739&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71739&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71739&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71739&r=mysqlcfg