Magento 2: Deprecated Functionality: substr(): Passing null to parameter #1 ($string) of type string is deprecated (Bugfix) Print

  • M2
  • 0

Issue:

Error in Magento Migration Tool - Deprecated Functionality

When using the Magento Migration Tool, specifically version 2.4.5, for data migration, you may encounter the following error near the end of the data migration step:

In ErrorHandler.php line 62:
  
  Deprecated Functionality: substr(): Passing null to parameter #1 ($string) of type string is deprecated in vendor/magento/data-migration-tool/src/Migration/Handler/SetValue.php on line 35

This error occurs due to deprecated functionality in the code related to the use of the substr() function. However, there is a simple fix to address this issue.

Fix / Workaround:

To resolve this error, follow the steps outlined below:

  • Open the file vendor/magento/data-migration-tool/src/Migration/Handler/SetValue.php.
  • Replace the existing code around line 35:

    $operator = substr($this->value, 0, 1);
    $value = substr($this->value, 1);

    With the updated code:

    $operator = ($this->value !== null && is_string($this->value)) ? substr($this->value, 0, 1) : null;
    $value = ($this->value !== null && is_string($this->value)) ? substr($this->value, 1) : null;
  • Clear the Magento cache:

    php bin/magento cache:clean

If you are a Create Hosting customer utilising our MageVPS Plan, feel free to submit a support ticket and we can investigate and take care of this issue for you.


Was this answer helpful?

« Back