Skip to content

Variable-length argument lists are not supported by Interceptor generation #20430

@xi-ao

Description

@xi-ao

Preconditions (*)

On Magento 2.0/2.1/2.2.

  1. Create an interceptable class, for example \Foo\Bar\Controller\Index (extending \Magento\Framework\App\Action\Action)
  2. Add a method using the variable-length argument list notation:
    public function hook($hook, &...$params)
    {
        if (method_exists($this, $hook)) {
            return call_user_func_array([$this, $hook], $params);
        }
    }

Steps to reproduce (*)

  1. Access this controller to trigger the generation of the Interceptor class in developer mode.

Expected result (*)

  1. The controller should render what's defined in the execute() method.

Actual result (*)

Warning: Declaration of Foo\Bar\Controller\Index\Interceptor::hook($hook, &$params) should be compatible with Foo\Bar\Controller\Index::hook($hook, &...$params) in /var/www/var/generation/Foo/Bar/Controller/Index/Interceptor.php on line 8
#0 /var/www/var/generation/Foo/Bar/Controller/Index/Interceptor.php(8): MBaro\Framework\App\ErrorHandler->handler(2, 'Declaration of ...', '/var/www/mBar...', 8, Array)
#1 /var/www/vendor/mBaro/framework/Code/Generator/Io.php(158): include('/var/www/mBar...')
#2 /var/www/vendor/mBaro/framework/Code/Generator.php(108): MBaro\Framework\Code\Generator\Io->includeFile('/var/www/mBar...')
#3 /var/www/vendor/mBaro/framework/Code/Generator/Autoloader.php(35): MBaro\Framework\Code\Generator->generateClass('Foo\\Bar\\Con...')
#4 [internal function]: MBaro\Framework\Code\Generator\Autoloader->load('Foo\\Bar\\Con...')
#5 [internal function]: spl_autoload_call('Foo\\Bar\\Con...')
#6 /var/www/vendor/mBaro/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Foo\\Bar\\Con...')
#7 /var/www/vendor/mBaro/framework/ObjectManager/Definition/Runtime.php(44): MBaro\Framework\Code\Reader\ClassReader->getConstructor('Foo\\Bar\\Con...')
#8 /var/www/vendor/mBaro/framework/ObjectManager/Factory/Dynamic/Developer.php(71): MBaro\Framework\ObjectManager\Definition\Runtime->getParameters('Foo\\Bar\\Con...')
#9 /var/www/vendor/mBaro/framework/ObjectManager/ObjectManager.php(57): MBaro\Framework\ObjectManager\Factory\Dynamic\Developer->create('Foo\\Bar\\Con...', Array)
#10 /var/www/vendor/mBaro/framework/App/ActionFactory.php(37): MBaro\Framework\ObjectManager\ObjectManager->create('Foo\\Bar\\Con...')
#11 /var/www/vendor/mBaro/framework/App/Router/Base.php(300): MBaro\Framework\App\ActionFactory->create('Foo\\Bar\\Con...')
#12 /var/www/vendor/mBaro/framework/App/Router/Base.php(161): MBaro\Framework\App\Router\Base->matchAction(Object(MBaro\Framework\App\Request\Http), Array)
#13 /var/www/vendor/mBaro/framework/App/FrontController.php(50): MBaro\Framework\App\Router\Base->match(Object(MBaro\Framework\App\Request\Http))
#14 [internal function]: MBaro\Framework\App\FrontController->dispatch(Object(MBaro\Framework\App\Request\Http))
#15 /var/www/vendor/mBaro/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#16 /var/www/vendor/mBaro/framework/Interception/Chain/Chain.php(70): MBaro\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#17 /var/www/vendor/mBaro/framework/Interception/Interceptor.php(136): MBaro\Framework\Interception\Chain\Chain->invokeNext('MBaro\\Framewo...', 'dispatch', Object(MBaro\Framework\App\FrontController\Interceptor), Array, 'install')
#18 /var/www/vendor/mBaro/framework/Module/Plugin/DbStatusValidator.php(69): MBaro\Framework\App\FrontController\Interceptor->MBaro\Framework\Interception\{closure}(Object(MBaro\Framework\App\Request\Http))
#19 [internal function]: MBaro\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(MBaro\Framework\App\FrontController\Interceptor), Object(Closure), Object(MBaro\Framework\App\Request\Http))
#20 /var/www/vendor/mBaro/framework/Interception/Interceptor.php(140): call_user_func_array(Array, Array)
#21 /var/www/var/generation/MBaro/Framework/App/FrontController/Interceptor.php(26): MBaro\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#22 /var/www/vendor/mBaro/framework/App/Http.php(115): MBaro\Framework\App\FrontController\Interceptor->dispatch(Object(MBaro\Framework\App\Request\Http))
#23 /var/www/vendor/mBaro/framework/App/Bootstrap.php(258): MBaro\Framework\App\Http->launch()
#24 /var/www/pub/index.php(37): MBaro\Framework\App\Bootstrap->run(Object(MBaro\Framework\App\Http))
#25 {main}

Because in the interceptor, the method has been declared as follows:

    /**
     * {@inheritdoc}
     */
    public function hook($hook, &$params)
    {
        $pluginInfo = $this->pluginList->getNext($this->subjectType, 'hook');
        if (!$pluginInfo) {
            return parent::hook($hook, $params);
        } else {
            return $this->___callPlugins('hook', func_get_args(), $pluginInfo);
        }
    }

Metadata

Metadata

Assignees

Labels

Issue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions