0

I have an issue;

1 exception(s): Exception #0 (Exception): Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222 Which is ;

// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove "foo\"bar"
$sql = preg_replace("/\"(\\\\\"|[^\"])*\"/Us", '', $sql);
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the value used as an escaped delimited id quote,
// e.g. \" or "" or \`
$de = $this->_adapter->quoteIdentifier($d);
$de = substr($de, 1, 2);
$de = preg_quote($de);
// Note: $de and $d where never used..., now they are:
(222) $sql = preg_replace("/$d($de|\\\\{2}|[^$d])*$d/Us", '', $sql);
return $sql;
}

My code is :

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
$_product = $block->getProduct();

$specs = $_product->getAttributeText('specifications');
$specs = $specs = $this->helper('Magento\Catalog\Helper\Output')- 
>productAttribute($block->getProduct(), $block->getProduct()- 
>getSpecifications(), 'specifications');

$specs = trim( str_replace( array("\r\n","\r", "<br />" ),"", $specs));
$specs = trim( html_entity_decode( $specs ) );

Sample output of the my code:

enter image description here

2
  • Where is preg_replace in the code you provided?
    – elfling
    Jan 10, 2023 at 11:08
  • any update on this? I migrated to a another vps and updated from 2.3.4 to 2.4.5 and PHP7.3 to PHP8.1. I only got this error in line 222 on the homepage. Thank's in advanced, Edwin
    – Edwin
    Feb 6, 2023 at 21:12

2 Answers 2

0

Update below line :

$specs = trim( str_replace( array("\r\n","\r", "" ),"", $specs ) );

to

if($specs){
  $specs = trim( str_replace( array("\r\n","\r", "" ),"", $specs ) );
}
4
  • it didnt work ..
    – Gkna
    Jan 7, 2023 at 16:18
  • As per your error message, Your 3rd parameter is NULL in str_replace. Jan 8, 2023 at 10:57
  • I added a screenshoot of output
    – Gkna
    Jan 12, 2023 at 20:45
  • @Gkna how to fix this
    – User0434
    Jan 18, 2023 at 14:06
0

It's occurring due to the $sql variable being null. You need to check $sql variable contains a value or not.

Till PHP7.4 this method was runs without any error, from PHP8.1 it throws an error.

To solve this issue please add a (string) type for the $sql variable.

Please try the below way. I hope It'll not throw any errors.

echo $sql = preg_replace("/\"(\\\\\"|[^\"])*\"/Us", '', (string) $sql);

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.