Skip to content

Interface constructor if present will break Magento compilation #8607

@redboxmarcins

Description

@redboxmarcins

Preconditions

  1. Install latest Magento 2.x (tested on 2.0.x and 2.1.x) - PHP 5.6 or PHP 7.0
  2. Any custom module with interface defined

Steps to reproduce

  1. Create module and define Interface with __construct method
  2. Run php bin/magento setup:di:compile

Expected result

  1. Compilation should complete 100% as PHP allows interface to have constructor - I'm not saying it should have, but it can as language allows it - so compiler should honor that

Actual result

  1. Error: PHP Notice: Trying to get property of non-object in /var/www/html/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php on line 30

Problem is here

if (!$class->getFileName() || false == $class->hasMethod(

If class hasn't got '__construct' method it will be skipped, but if method exist

$class->getConstructor() will return NULL
and
$class->getConstructor()->class obviously will generate fatal error

Simplest fix

if (!$class->getFileName() || false == $class->hasMethod(
            '__construct'
        ) || !$inherited && null !== $class->getConstructor() && $class->getConstructor()->class != $class->getName()
        ) {
            return $output;
        }

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions