Magento – Override topmenu

magento2override-block

1 exception(s):
Exception #0 (Exception): Warning: Declaration of Vendor\Module\Block\Html\Topmenu::_addSubMenu(Magento\Framework\Data\Tree\Node $child, $childLevel, $childrenWrapClass, $limit) should be compatible with Magento\Theme\Block\Html\Topmenu::_addSubMenu($child, $childLevel, $childrenWrapClass, $limit) in D:\xampp\htdocs\prakash\demoes\magento213\app\code\Vendor\Module\Block\Html\Topmenu.php on line 3

Code of file "app\code\Vendor\Module\Block\Html\Topmenu.php" is as following:-

<?php
namespace Vendor\Module\Block\Html;
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
    protected function _addSubMenu( $child, $childLevel, $childrenWrapClass, $limit)
    {

    }
}

Above error comes while overriding topmenu. I'm beginner in magento Can anybody help me ?

Best Answer

While overriding any function, we must take care of the function signatures.

Function signature means, the scope, number of the parameters, type of the parameters of the base class function etc. This should be identical to the base function signature.

In your case, the scope is fine, but please check the parameters. This may fix your issue.

Related Topic