Magento2: M2.1.2 : Interceptor breaks when type hinting a string

Created on 30 Nov 2016  路  9Comments  路  Source: magento/magento2

I generated a block glass that has a method that takes a single string as parameter. I type-hinted the parameter in the method, but the generator interceptor doesn't take this into account. The result is an error.

Preconditions

Steps to reproduce

Create a method in a block class that has type-hinting for a string:

public function getFoo(string $foo)
{
    return $foo;
}

Make Magento re-generate it's var/generated-folder.

Expected result

No error thrown. Generated method in the interceptor should have the same signature.

Actual result

Magento throws an error:

Warning:
Declaration of Vendor\Module\Block\Foo\Interceptor::getFoo($foo) 
should be compatible with 
Vendor\Module\Block\Foo\Interceptor::getFoo(string $foo) 
in .../var/generation/Vendor\Module\Block\Foo\Interceptor.php on line 7

If you open the interceptor you see that the signature lacks the type hint. Which of course will throw an error since it's inherited:

public function getFoo($foo)
{
    $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getFoo');
    if (!$pluginInfo) {
        return parent::getFoo($imageId);
    } else {
        return $this->___callPlugins('getFoo', func_get_args(), $pluginInfo);
    }
}
Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Reproduced on 2.1.x bug report

Most helpful comment

Almost half a year later this problem still persists in Magento 2.1.7

Is there any update on this issue?

All 9 comments

Same issue applies to returned types (PHP7 functionality) generated interceptor code is missing return type causing error.

Is there any update on this?

Almost half a year later this problem still persists in Magento 2.1.7

Is there any update on this issue?

Same here. PHP 7.0.6, Magento 2.1.7

Duplicate of #6106. Fixed in develop but unlikely to be backported to 2.1. Not a bug, obviously, but limitation of third-party component used.

@kanduvisla, thank you for your report.
The issue is already fixed in develop branch, 2.2.0

@magento-engcom-team and backported to 2.1 I hope?

@Ctucker9233,

unlikely to be backported to 2.1

@orlangur Does it break BC? If it doesn't, I'll take a stab at it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreaskoch picture andreaskoch  路  3Comments

xi-ao picture xi-ao  路  3Comments

punkstar picture punkstar  路  3Comments

BenSpace48 picture BenSpace48  路  3Comments

jzalenski picture jzalenski  路  3Comments