Resolve an illegal offset error
This article provides a solution for when in Adobe Commerce 2.1 or later, you receive a Resolve an illegal offset error when creating a new product in the Commerce Admin.
In Adobe Commerce 2.1 or later, when creating a new product in the Commerce Admin, the following error might display:
Warning: Illegal string offset 'is_in_stock' in [...]/vendor/
Modifier/AdvancedInventory.php on line 87
Adobe Commerce 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
To find OPcache configuration settings:
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:
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.
Open your OPcache configuration file in a text editor.
opcache.save_comments and 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
Regenerate DI configuration and all missing classes that can be auto-generated:
$ bin/magento setup:di:compile`