Opened 3 years ago
Last modified 12 months ago
#14881 new defect (bug)
do_action should not pass empty string by default — at Initial Version
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Plugins | Version: | |
| Severity: | normal | Keywords: | has-patch 3.2-early |
| Cc: |
Description
function test( $a = true ) {
var_dump( $a );
}
add_action( 'test', 'test' );
add_action( 'test', 'test', 10, 0 );
do_action( 'test' );
First example is bool(true), but the second is a zero-length string.
In this case, since do_action() is not passing any arguments, then no arguments should be passed to test() -- even if by default, one argument gets passed.
The issue here is how do_action() is defined: function do_action( $tag, $arg = '' );. There's our zero-length string. Of note, apply_filters() does not have this same issue.
The solution looks something like what I have attached. Has yet to be benchmarked.
Of note, this does not appear to have any direct implications for passing all args by default, as proposed in #14671, but I wanted to reference it anyway.
