Magento version: 2.2.3

I have a Block class with a method to fetch the designer associated with a product. It is annotated to return a model interface or null.

public function getDesigner(): ?DesignerInterface {

When running Magento in production mode, the system compiles an interceptor class for this Block, but drops the ? in the annotation, resulting in this:

public function getDesigner(): DesignerInterface

This causes a fatal error on product pages where a product does not have a designer associated with it, as the method no longer accepts null as a return value.

First of all, why is Magento modifying my code? This throws a huge red flag for me.

Second, is there any way to disable this?

1 Answer 1


I later discovered that this is actually caused by a bug in Magento. Details can be found here: https://github.com/magento/magento2/issues/15505

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.