Opened 7 weeks ago
Closed 7 weeks ago
#63479 closed defect (bug) (fixed)
current_filter() can return false if fatal
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.9 | Priority: | normal |
Severity: | trivial | Version: | |
Component: | Plugins | Keywords: | has-patch commit has-test-info |
Focuses: | docs | Cc: |
Description
current_filter() (and current_action()) have a @return string
However both can return false when used in an exception handler callback, if there's a fatal/uncaught exception and the current code is not run on an action/filter - e.g. in WP core itself or if a plugin manually loads WP and executes code after requiring wp-load.php
The @return should be changed to string|false
Change History (7)
This ticket was mentioned in PR #8840 on WordPress/wordpress-develop by @debarghyabanerjee.
7 weeks ago
#1
- Keywords has-patch added
#3
@
7 weeks ago
- Keywords needs-test-info added
@debarghyabanerjee can you provide a testing case that reproduces the issue your patch is informing? (false for each function). You can add some code
#4
@
7 weeks ago
Hi @SirLouen, you can try out this snippet by simply adding it in the functions.php, please let me know in case of any doubts. Thanks.
<?php set_exception_handler( function ( $exception ) { var_dump( current_filter() ); var_dump( current_action() ); wp_die(); } ); throw new Exception( 'Test exception' );
#5
follow-up:
↓ 6
@
7 weeks ago
- Focuses docs added
- Keywords commit added; changes-requested removed
- Milestone changed from Awaiting Review to 6.9
The linked pull request looks good to me.
@SirLouen You can see the functions returning false via wp-cli wp eval "var_dump( current_filter() );"
and wp eval "var_dump( current_action() );"
.
#6
in reply to:
↑ 5
@
7 weeks ago
- Keywords has-test-info added; needs-test-info removed
Replying to peterwilsoncc:
The linked pull request looks good to me.
@SirLouen You can see the functions returning false via wp-cli
wp eval "var_dump( current_filter() );"
andwp eval "var_dump( current_action() );"
.
Basically, the idea to trigger false
is calling current_filter
in the middle of nowhere
✅ Reproduced.
Trac Ticket: Core-63479
## Problem
The @return annotations for current_action() and current_filter() are currently defined as string, but both functions can return false when called outside the context of any action or filter. This can occur in specific scenarios such as:
This mismatch between the documented return type and actual behavior can lead to incorrect assumptions and potential runtime issues.
## Solution
Update the @return annotations for both current_action() and current_filter() to string|false.