[wp-trac] [WordPress Trac] #51913: Potential `unsupported operand types` dashboard fatal on PHP8 + multisite + upload space check

WordPress Trac noreply at wordpress.org
Wed Dec 2 02:01:56 UTC 2020


#51913: Potential `unsupported operand types` dashboard fatal on PHP8 + multisite +
upload space check
---------------------------------------+--------------------------------
 Reporter:  iandunn                    |      Owner:  (none)
     Type:  defect (bug)               |     Status:  new
 Priority:  high                       |  Milestone:  5.6
Component:  Administration             |    Version:
 Severity:  major                      |   Keywords:  php8 needs-testing
  Focuses:  administration, multisite  |
---------------------------------------+--------------------------------
 After upgrading my local environment to PHP 8, and a test site to the 5.6
 branch, I got a fatal error in the `At A Glance` dashboard widget.

 {{{
 PHP Fatal error:  Uncaught TypeError: Unsupported operand types: array /
 int in /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 includes/ms-functions.php:2635
 Stack trace:
 #0 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 admin/includes/dashboard.php(1549): get_space_used()
 #1 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 includes/class-wp-hook.php(287): wp_dashboard_quota('')
 #2 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
 #3 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 includes/plugin.php(484): WP_Hook->do_action(Array)
 #4 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 admin/includes/dashboard.php(411): do_action('activity_box_en...')
 #5 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 admin/includes/template.php(1389): wp_dashboard_right_now('', Array)
 #6 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 admin/includes/dashboard.php(265): do_meta_boxes(Object(WP_Screen),
 'column4', '')
 #7 /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu/wp-
 admin/index.php(181): wp_dashboard()
 #8 {main}
   thrown in /Users/iandunn/vhosts/localhost/wordcamp.test/public_html/mu
 /wp-includes/ms-functions.php on line 2635
 }}}

 This seems related to the caching added in r49212 (#19879), cc @helen.

 `get_dirsize()` and `recurse_dirsize()` returned an array instead of an
 int. `return $directory_cache[ $cache_path ]` was expecting that value to
 be an int, but instead it was `array( 'size' => 0 )`.

 I don't see how it could be created like this, but the transient value
 was:

 {{{
 a:1:{s:94:"/Users/iandunn/vhosts/localhost/wp-
 develop.test/public_html/build/wp-
 content/blogs.dir/2/files";a:1:{s:4:"size";i:0;}}
 }}}

 In PHP7 the arguments of `get_dirsize( $upload_dir['basedir'] ) /
 MB_IN_BYTES` would have been silently cast to match types,
 [https://wiki.php.net/rfc/arithmetic_operator_type_checks but in PHP8 it's
 a fatal error].

 The error is no longer happening on my test site, and '''I haven't been
 able to reproduce it in a fresh install''', so this may be `invalid`.
 There doesn't appear to be any 3rd party code related to this behavior,
 though. Since the 5.6 release date is only a week away, and it's had a
 relatively small amount of real-world testing w/ PHP 8, I thought it'd be
 prudent to get some more eyes on this.

 `get_dirsize()` is only called in Multisite, but `recurse_dirsize()` is
 called by single site, so there may be other instances of a similar
 problem.


 -----

 == Trying to reproduce:

 Before I upgraded and got the error, my environment looked like this:

 * PHP 7.2
 * WP 5.5 branch via SVN, probably a few weeks behind the head
 * Multisite
 * `upload_space_check_disabled` = `0`

 I installed PHP 8.0.0, then `svn sw ^/branches/5.6` (head was r49734 at
 the time of writing this)

 IIRC, I encountered the error on the main site, which affects the
 execution path in `get_dirsize()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51913>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list