Opened 4 years ago
Closed 4 years ago
#51697 closed defect (bug) (reported-upstream)
[PHP8] Uncaught TypeError: array_flip():
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 5.6 |
Component: | Administration | Keywords: | php8 |
Focuses: | Cc: |
Description (last modified by )
while using trunk on php8 I ran into this error, when i try to access wp-admin pages.
Fatal error: Uncaught TypeError: array_flip(): Argument #1 ($array) must be of type array, null given in public_html/wp-admin/includes/menu.php:280 Stack trace: #0 public_html/wp-admin/includes/menu.php(280): array_flip(NULL) #1 public_html/wp-admin/menu.php(327): require_once('/home/customer/...') #2 public_html/wp-admin/admin.php(158): require('/home/customer/...') #3 public_html/wp-admin/index.php(10): require_once('/home/customer/...') #4 {main} thrown in public_html/wp-admin/includes/menu.php on line 280
Change History (8)
#4
@
4 years ago
- Component changed from Menus to Administration
- Description modified (diff)
- Milestone changed from Awaiting Review to 5.6
#6
@
4 years ago
Noting that I was seeing a warning to this effect while running PHP 7.4.12. GB26643 fixed it.
Note: See
TracTickets for help on using
tickets.
Hi @bph, thanks for reporting this!
This is not necessarily an issue with WP Core, but more likely an issue with a plugin or theme doing it wrong.
Relevant code in
wp-admin/includes/menu.php
:$menu_order
is an array and get pulled through themenu_order
filter just before thearray_flip()
, so one of the functions filtering the variable will have broken things by either not returning anything or by returningnull
.Now, it is tempting to add an
(array)
cast to fix this or to wrap the rest of the body of the condition in anif ( is_array( $menu_order ) ) {}
, but that would only serve to hide the problem, not actually fix it.This is a typical example of a filter which would really benefit from a type safe variant of
apply_filters()
as proposed in #51525.For now, @bph, I'd like to ask you gather some more information either by using the Query Monitor or by using the Debug Bar Actions & Filter addon.
To figure out which plugin/theme/Core is causing the issue, we need to know what functions are hooked into the
menu_order
filter and where they are coming from (plugin/theme/Core) and if plugin/theme, preferably including information on which version of the plugin/theme you are using.Once that information is available, all functions listed will need to be examined to figure out the culprit.