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:
Warning: Illegal string offset 'is_in_stock' in [...]/vendor/ magento/module-catalog-inventory/Ui/DataProvider/Product/Form/ Modifier/AdvancedInventory.php on line 87
Magento 2.1 and later use PHP code comments in the
getDocComment validation call in the
getExtensionAttributes method in
If you enabled the PHP OPcache (which we recommend), this error displays because by default, the OPcache setting
opcache.save_comments is disabled.
To solve the issue, locate your OPcache configuration settings and enable
opcache.save_comments as follows:
Step 1: Locate your OPcache configuration
PHP OPcache settings are typically located either in
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
Use the following guidelines to find it:
Apache web server:
For Ubuntu with Apache, OPcache settings are typically located in
For CentOS with Apache or nginx, OPcache settings are typically located in
If not, use the following command to locate it:
sudo find / -name 'opcache.ini'
nginx web server with PHP-FPM:
If you have more than one
opcache.ini, modify all of them.
Step 2: Enable
- Open your OPcache configuration file in a text editor.
opcache.save_commentsand uncomment it if necessary.
- Make sure its value is set to
- Save your changes and exit the text editor.
Restart your web server:
- Apache, Ubuntu:
service apache2 restart
- Apache, CentOS:
service httpd restart
- nginx, Ubuntu and CentOS:
service nginx restart
- Apache, Ubuntu:
Regenerate DI configuration and all missing classes that can be auto-generated:
php bin/magento setup:di:compile