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.
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.
No error thrown. Generated method in the interceptor should have the same signature.
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);
}
}
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.
Most helpful comment
Almost half a year later this problem still persists in Magento 2.1.7
Is there any update on this issue?