[nycphp-talk] How does one suggest improved variable scoping for PHP?
Jeremy Mikola
jmikola at gmail.com
Wed Nov 16 11:41:53 EST 2011
The concept of "regional" variables you're describing already exists via
use statements for anonymous functions. The following should be possible:
function array_sanitize($array, $filter) {
$negFilter = function($arg) use ($filter) {
return !$filter($arg);
};
return array_filter($array, $negFilter)
}
See example #3 here: http://php.net/manual/en/functions.anonymous.php
On Wednesday, November 16, 2011, Jim Williams <jim at pagenotes.com> wrote:
> I just ran across a simple problem I couldn't solve, namely to create a
function that does the opposite of array_filter, call it array_sanitize.
The closest I could come doesn't work for anonymous functions:
>
> <?php
> function array_sanitize($array, $filterName) {
> $negFilter = create_function('$arg', 'return !'.$filterName.'($arg);');
> return array_filter($array, $negFilter);
> }
> //Example:
> $a = array('a'=>6,'b'=>1,'c'=>4,'d'=>9);
> function isOdd($arg) { return $arg % 2 == 1; }
> print_r (array_sanitize($a, 'isOdd')); // outputs 'Array ( [a] => 6 [c]
=> 4 )'
> ?>
>
> If we had variables of intermediate scope, call them "regional"
variables, we could do this:
> /*
> function array_sanitize($array, $filter) {
> $negFilter = function($arg) {
> regional $filter;
> return !$filter($arg)
> };
> return array_filter($array, $negFilter)
> }
> */
>
> So, my question is how and whether to advocate the need for variables of
intermediate scope.
> Specifically, is there a public forum for suggesting improvements to PHP?
>
> Jim Williams
> J. G. Williams Design
>
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/Show-Participation
>
--
jeremy mikola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20111116/4f0ff097/attachment.html>
More information about the talk
mailing list