[wp-trac] [WordPress Trac] #10493: Allow closures as callbacks
WordPress Trac
wp-trac at lists.automattic.com
Thu Oct 22 20:37:06 UTC 2009
#10493: Allow closures as callbacks
-------------------------+--------------------------------------------------
Reporter: scribu | Owner: scribu
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: General | Version: 2.9
Severity: normal | Keywords: has-patch
-------------------------+--------------------------------------------------
Comment(by scribu):
> I'm not sure we __need__ to do this.
As of [12090], we could do this:
{{{
add_action('init', array(function() { // do something }));
}}}
but eliminating the array() is easily done with
[http://core.trac.wordpress.org/attachment/ticket/10493/closures.2.diff
closures.2.diff]
> We shouldn't be encouraging create_function in this case anyway as there
are possible security risk.
Precisely: You can't create closures in the same way you can pass a string
to create_function(), so it's actually encouraging safer code.
> Closures make it easier to write multi-line functions here which make
the code even harder to read.
It's the same as closures in jQuery. Here's a counter example:
{{{
add_action('init', function() {
if ( isset($_GET['restricted']) )
die('Not so fast...');
});
}}}
Looks familiar? :-)
> Also looking at the php docs the fact that they are currently
implemented by the Closure class should not be relied on.
closures.2.diff doesn't rely on that anymore.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10493#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list