Make WordPress Core

Opened 9 months ago

Closed 8 months ago

#64728 closed defect (bug) (fixed)

Using null as an array offset is deprecated in PHP 8.5.3

Reported by: sky_76 Owned by: westonruter
Priority: normal Milestone: 7.0
Component: Toolbar Version: 6.9.1
Severity: minor Keywords: has-patch commit
Cc: Focuses:

Description

Error message when using PHP 8.5.3 over PHP 8.4.18:

Deprecated: Using null as an array offset is deprecated, use an empty string instead in wp-includes/class-wp-admin-bar.php on line 172

(The error is shown right below the Admin Bar)

Change History (7)

This ticket was mentioned in ​PR #11055 on ​WordPress/wordpress-develop by ​@westonruter.


9 months ago
#1

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/64728

## Use of AI Tools

n/a

#2 follow-up: @westonruter
9 months ago

  • Keywords reporter-feedback needs-testing added
  • Milestone Awaiting Review → 7.0

@sky_76 I tried logging out $args['parent'] on that line and it is always either a string or false. Perhaps you have a plugin that registers an admin menu node with a parent supplied as null? Can you log out the $args to find out what plugin/theme that is?

In any case, it makes sense to improve the type checking here. I've opened ​https://github.com/WordPress/wordpress-develop/pull/11055 to fix. Please test that as well.

#3 @sabernhardt
9 months ago

  • Component Administration → Toolbar

#4 in reply to: ↑ 2 @sky_76
9 months ago

Replying to westonruter:

@sky_76 I tried logging out $args['parent'] on that line and it is always either a string or false. Perhaps you have a plugin that registers an admin menu node with a parent supplied as null? Can you log out the $args to find out what plugin/theme that is?

In any case, it makes sense to improve the type checking here. I've opened ​https://github.com/WordPress/wordpress-develop/pull/11055 to fix. Please test that as well.

Ok, I am so sorry, it is just one plugin that is the culprit:

    [id] => omgf
    [title] => OMGF
    [parent] => 
    [href] => https://mydomainname.com/wp-admin/options-general.php?page=optimize-webfonts
    [group] => 
    [meta] => Array
        (
        )

Maybe best to set this to "wontfix"? Again, sorry for that.

#5 @ozgursar
9 months ago

  • Keywords needs-testing removed

Patch Testing Report

Patch Tested: ​https://github.com/WordPress/wordpress-develop/pull/11055

Environment

  • WordPress: 7.0-beta1-20260225.235833
  • PHP: 8.5.2
  • Server: PHP.wasm
  • Database: WP_SQLite_Driver (Server: 8.0.38 / Client: 3.51.0)
  • Browser: Chrome 145.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Code Snippets 3.9.5
    • Test Reports 1.2.1

Steps taken

  1. Initiate WordPress Playground with the following link:

​https://playground.wordpress.net/?php=8.5&wp=trunk

  1. Add the following code via functions.php or Code Snippets plugin to trigger the PHP notice
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
    $wp_admin_bar->add_node( [
        'id'     => 'my-test-node',
        'title'  => 'Test Node',
        'parent' => null,
    ] );
}, 999 );
  1. Ensure WP_DEBUG and WP_DEBUG_LOG are true
  2. Check /wp-content/debug.log to view the notice:

PHP Deprecated: Using null as an array offset is deprecated, use an empty string instead in /wordpress/wp-includes/class-wp-admin-bar.php on line 172

  1. Apply patch

​https://playground.wordpress.net/?php=8.5&wp=trunk&core-pr=11055

  1. Repeat steps 2-4
  2. Confirm that PHP Deprecated notice does not occur
  3. ✅ Patch is solving the problem

Expected result

  • No further PHP Deprecated notices logged when parent is null

Screenshots/Screencast with results

Before patch
https://i.imgur.com/J8JHsNH.png

After patch
https://i.imgur.com/aEy4rjE.png

#6 @westonruter
9 months ago

  • Keywords commit added; reporter-feedback removed
  • Owner set to westonruter
  • Status new → accepted

@ozgursar Thanks for that. Given that the issue was reproduced and the PR fixes the issue, this seems like something worthwhile to commit for core's overall type hardening and improved PHP compatibility.

#7 @westonruter
8 months ago

  • Resolution → fixed
  • Status accepted → closed

In 61997:

Toolbar: Prevent PHP deprecation warning in admin bar when node is added with a null parent.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11055

Props sky_76, westonruter, ozgursar, sabernhardt.
Fixes #64728.

Note: See TracTickets for help on using tickets.