Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.

Resolve an illegal offset error

In Magento 2.1 or later, when creating a new product in the Magento Admin, the following error might display:

1
2
3
Warning: Illegal string offset 'is_in_stock' in [...]/vendor/
magento/module-catalog-inventory/Ui/DataProvider/Product/Form/
Modifier/AdvancedInventory.php on line 87

Detail

Magento 2.1 and later use PHP code comments in the getDocComment validation call in the getExtensionAttributes method in Magento\Framework\Api\ExtensionAttributesFactory.php.

If you enabled the PHP OPcache (which we recommend), this error displays because by default, the OPcache setting opcache.save_comments is disabled.

Workaround

To solve the issue, locate your OPcache configuration settings and enable opcache.save_comments as follows:

Step 1: Locate your OPcache configuration

To find OPcache configuration settings:

PHP OPcache settings are typically located either in php.ini or opcache.ini. The location might depend on your operating system and PHP version. The OPcache configuration file might have an [opcache] section or settings like opcache.enable.

Use the following guidelines to find it:

  • Apache web server:

    For Ubuntu with Apache, OPcache settings are typically located in php.ini.

    For CentOS with Apache or nginx, OPcache settings are typically located in /etc/php.d/opcache.ini

    If not, use the following command to locate it:

    1
    
    sudo find / -name 'opcache.ini'
    
  • nginx web server with PHP-FPM: /etc/php5/fpm/php.ini

If you have more than one opcache.ini, modify all of them.

Step 2: Enable opcache.save_comments

  1. Open your OPcache configuration file in a text editor.
  2. Locate opcache.save_comments and uncomment it if necessary.
  3. Make sure its value is set to 1.
  4. Save your changes and exit the text editor.
  5. Restart your web server:

    • Apache, Ubuntu: service apache2 restart
    • Apache, CentOS: service httpd restart
    • nginx, Ubuntu and CentOS: service nginx restart
  6. Regenerate DI configuration and all missing classes that can be auto-generated:

    • bin/magento setup:di:compile
Updated