Fix PHPStan undefined variables in menu.php and network.php#11014
Fix PHPStan undefined variables in menu.php and network.php#11014huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| } | ||
|
|
||
| // Create list of page plugin hook names. | ||
| global $menu, $submenu, $compat; |
There was a problem hiding this comment.
Great catch on the PHPStan warnings!
Quick question:
since wp-admin/menu.php (line 440) loads includes/menu.php via require, both files share the same scope. So $menu, $submenu, and $compat should already be accessible without global.
Do you think PHPStan is flagging this because it analyzes the file in isolation? Just curious about the reasoning. The network.php fix looks solid!
This fixes a few PHPStan "variable might not be defined" warnings..
Changes:
src/wp-admin/includes/menu.php: Added theglobaldeclaration for$menu,$submenu, and$compat.src/wp-admin/includes/network.php: Initialized the$messageand$message_classvariables to prevent them from being undefined when the condition isn't met.Trac: https://core.trac.wordpress.org/ticket/64238