magento2: Magento 2.2.0 does not support nullable return types on PHP 7.0.24

Preconditions

  1. Magento 2.2.0
  2. PHP 7.0.24

Steps to reproduce

Checking the system requirements for Magento 2.2.0 on http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements-tech.html#php it shows that PHP 7.0 is supported, however the VarTag.php file under vendor/zendframework/zend-code/src/Reflection/DocBlock/Tag/ contains a few methods which returns nullable return types. Like the methods below:

public function getVariableName() : ?string
{
    return $this->variableName;
}

public function getDescription() : ?string
{
    return $this->description;
}

The nullable return types are not yet supported on PHP7.0. They were introduced from PHP7.1 on. This means that the actions using the methods above (like the login action) thrown syntax error. Please correct the system requirements.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (14 by maintainers)

Most upvoted comments

@mzeis agree with @orlangur Magento itself should not add platform to the distributed composer.json. However any developer/agency that is installing and working in a mixed php version environment should add platform to their own copy of composer.json to avoid exactly this type of issue.

The issue that we do have is that Magento pre-generates a zip download available here https://magento.com/tech-resources/download for Magento 2.2 that makes a determination on behalf of the user and generates under php 7.0. (the zip comes with zend/code 3.1.0)

What Magento should do (if they want to continue offering the zip download) is, at a minimum, use platform 7.0 and 7.1 to create two separate zip downloads (I’ll create a separate issue for this).

@esimov can you confirm if you do have a mixed environment of php versions or if you are already using platform or ignore platform reqs? I did an upgrade from 2.1.9 to 2.2.0 via composer on php 7.0 and ended up with the right version:

$ composer show zendframework/zend-code
name     : zendframework/zend-code
descrip. : provides facilities to generate arbitrary code using an object oriented interface
keywords : code, zf2
versions : * 3.1.0

@orlangur also tested the following on 7.1

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition m2
$ cd m2
$ bin/magento install _____
...
$ composer show zendframework/zend-code
name     : zendframework/zend-code
descrip. : provides facilities to generate arbitrary code using an object oriented interface
keywords : code, zf2
versions : * 3.2.0
$ bin/magento setup:di:compile
Compilation was started.
Interception cache generation... 7/7 [============================] 100% 17 secs 244.0 MiB
Generated code and dependency injection configuration successfully.

seems something is missing from @ytorbyk steps.

Just to copy from the other thread, i believe that if you run PHP7.1 CLI version for composer, and run PHP 7.0 on PHP-FPM, the Magento should warn administrator that something is broken, because users may get unexpected blank screens on unknown places (everywhere where php 7.1 specifi code is used) when php get parse error…

I also agree that if you install using cli 7.1, fpm should be 7.1+, but if webmaster do not notice or forget to update php on webserver, he should get notified somehow…

Strange that it wasn’t revealed by integration tests. Is this code actually used in Magento 2? Could you provide some scenario?

Looks like 3.1.0 release of Zend_Code didn’t support PHP 7.1: https://github.com/zendframework/zend-code/blob/release-3.1.0/composer.json#L16 While 3.2.0 release does not support PHP 7.0: https://github.com/zendframework/zend-code/blob/release-3.2.0/composer.json#L16

Thus there are only two options for Magento 2 to solve the problem directly:

  • drop PHP 7.0 support
  • maintain separate composer files for PHP 7.0 and PHP 7.1

Indirect solution is to fully cover all code which relies on Zend_Code with integration tests so that PHP 7.0 workability is preserved.