[wp-trac] [WordPress Trac] #14671: Deprecate the "accepted args" argument in add_filter() and add_action()

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 23 06:15:44 UTC 2010


#14671: Deprecate the "accepted args" argument in add_filter() and add_action()
-------------------------+--------------------------------------------------
 Reporter:  markjaquith  |       Owner:     
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.1
Component:  Plugins      |     Version:     
 Severity:  normal       |    Keywords:     
-------------------------+--------------------------------------------------

Comment(by markjaquith):

 <blockquote>Removal of a feature will break backwards
 compatibility</blockquote>

 Re-read the ticket. You don't understand it.

 <blockquote>If memory serves, there is huge harm in passing more arguments
 than needed to php's built-in functions.</blockquote>

 That was the sort of gotcha I was looking for, but I think we can overcome
 it.

 We could keep the argument, but set the default number of args to one for
 built-in PHP functions.

 This increases peak memory usage by 55K, and uses between 1 and 1.5 ms to
 generate the initial list. Total time cost on my system, with 388 calls is
 2.5 ms.

 {{{
 function is_internal_php_function( $function_name ) {
         global $php_internal_functions;
         if ( !isset( $php_internal_functions ) ) {
                 $functions = get_defined_functions();
                 $php_internal_functions = array_flip(
 $functions['internal'] );
         }
         return isset( $php_internal_functions[$function_name] );
 }
 }}}

 But only a very small subset of those internal PHP functions are ever used
 in WordPress filters. We might be able to just manually enumerate them,
 and set the {{{$accepted_args}}} to 1 by default for those.

 WordPress itself only uses three PHP internal functions in filters:

 > trim(), strip_tags(), and urldecode()

 I can think of a few other useful ones ({{{intval()}}}, for instance.

 In either case, we'd be keeping the optional argument, just choosing a
 more intuitive default, to remove the necessity for {{{10,2}}} nonsense.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14671#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list