报错:Warning: Declaration of description_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker…
导读WordPress 自定义导航菜单类报出 start_el 方法参数与 Walker_Nav_Menu 父类不兼容的警告,常见于旧主题或插件升级到新版 PHP 之后。内容说明警告成因,即子类重写时缺少默认值与 current_object_id 参数、变量名不一致
错误详情:
Warning: Declaration of description_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $data_object, $depth = 0, $args = NULL, $current_object_id = 0) in
你遇到的这个警告,核心原因是自定义导航菜单类 description_walker 重写的 start_el 方法,参数列表和 WordPress 核心父类 Walker_Nav_Menu 不匹配,PHP 抛出兼容警告。
解决办法:
父类 Walker_Nav_Menu 的 start_el 方法标准参数为:
public function start_el(&$output, $data_object, $depth = 0, $args = null, $current_object_id = 0)
而你的子类 description_walker 的 start_el 方法参数缺少默认值和最后一个参数,且变量名 $item 与父类的 $data_object 不一致,导致兼容警告。





![表情[qiang]-A8源码网](https://www.a8ymw.com/wp-content/themes/zibll/img/smilies/qiang.gif)
,谁懂
没有回复内容