"I must not fear. Fear is the mind-killer..." --Bene Gesserit Litany Against Fear

Magento 2 core code contribution #3

Friday, August 20th, 2021

I encountered a problem using the /rest/all/V1/products/ endpoint in Magento 2. The error message reported back to the API call was:

[message] => The product was unable to be saved. Please try again.

I had to add some extended logging to the affected Magento 2 method to determine the actual cause of the failure since it was not producing any usable log entries.

After adding getMessage() to one of the thrown exceptions, I was able to see the following full error message:

Deprecated Functionality: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in vendor/magento/module-catalog/Model/Product/Option/Repository.php on line 234.

In php 7.4, the PHP method array_key_exists() is deprecated and it was enough to stop Magento 2 before successfully completing the API transaction.

I was able to fix the problem by replacing the function with isset().

Magento 2 pull request on Github


I wrote a small module that will patch this in the meantime that you can download here. Install the module in app/code then run:

bin/magento c:f
bin/magento set:up
bin/magento setup:static-content:deploy


I submitted the core fix to Magento 2: https://github.com/magento/magento2/pull/33878/files

Views: 213