Opened 5 weeks ago
Last modified 4 weeks ago
#65786 reviewing defect (bug)
PHP Warning: Undefined property: stdClass::$current
| Reported by: | babola | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Menus | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
I have literally over a million of these in my PHP log file over the past week:
[26-Jul-2026 00:07:03 America/Los_Angeles] PHP Warning: Undefined property: stdClass::$current in /var/www/sites/XXX/wp-includes/class-walker-nav-menu.php on line 265
I'm running WordPress v7.0.2 on this version of AWS Linux:
[root@xxxxxxxx php-fpm]# uname -a Linux xxxxxxxx.yyyyyyyy.com 6.1.175-219.359.amzn2023.aarch64 #1 SMP Thu Jun 25 14:44:50 UTC 2026 aarch64 aarch64 aarch64 GNU/Linux
Here is my PHP version:
[root@xxxxxxxx php-fpm]# php -v
PHP 8.2.32 (cli) (built: Jul 1 2026 07:57:51) (NTS gcc aarch64)
Copyright (c) The PHP Group
Zend Engine v4.2.32, Copyright (c) Zend Technologies
with Zend OPcache v8.2.32, Copyright (c), by Zend Technologies
And here is the offending code in context:
[root@xxxxxxxx php-fpm]# sed -n '260,270p' /var/www/sites/XXX/wp-includes/class-walker-nav-menu.php
$atts['href'] = $menu_item->url;
} else {
$atts['href'] = '';
}
$atts['aria-current'] = $menu_item->current ? 'page' : '';
// Add title attribute only if it does not match the link text (before or after filtering).
if ( ! empty( $menu_item->attr_title )
&& trim( strtolower( $menu_item->attr_title ) ) !== trim( strtolower( $menu_item->title ) )
&& trim( strtolower( $menu_item->attr_title ) ) !== trim( strtolower( $the_title_filtered ) )
[root@xxxxxxxx php-fpm]#
My proposed fix to line 265 is simply to do a null coalesce:
$atts['aria-current'] = ($menu_item->current ?? '') ? 'page' : '';
Let me know if you need any more information, or if I need to clarify anything.
Thanks for your attention to this matter!
Change History (3)
This ticket was mentioned in PR #12805 on WordPress/wordpress-develop by @deepakbhojwani.
5 weeks ago
#1
- Keywords has-patch has-unit-tests added; needs-patch removed
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## Summary
Walker_Nav_Menu::start_el()reads$menu_item->currentdirectly to build thearia-currentattribute. When a menu item object reaches the walker without going through_wp_menu_item_classes_by_context()(e.g. custom walkers, filtered or cached menu items), thecurrentproperty is never set, which triggers aPHP Warning: Undefined property: stdClass::$currenton PHP 8.2+.This wraps the check in
empty(), matching how the other optional menu item properties (target,xfn,url,attr_title,classes) are already handled in this same method.## Test plan
test_start_el_should_not_warn_when_current_property_is_not_set()intests/phpunit/tests/menu/walker-nav-menu.php, which callsstart_el()with a menu item object that intentionally omitscurrentand asserts noaria-currentattribute is output (fails without the fix, passes with it).