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

asked Jan 7, 2023 at 15:15
2
  • Where is preg_replace in the code you provided? Commented 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 Commented Feb 6, 2023 at 21:12

3 Answers 3

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 ) );
}
answered Jan 7, 2023 at 15:42
4
  • it didnt work .. Commented Jan 7, 2023 at 16:18
  • As per your error message, Your 3rd parameter is NULL in str_replace. Commented Jan 8, 2023 at 10:57
  • I added a screenshoot of output Commented Jan 12, 2023 at 20:45
  • @Gkna how to fix this Commented 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

answered Jun 2, 2023 at 14:17
0

I had the same error. In my case it was caused by MageWorx_SeoMarkup module. In my short time researching this I figured out that apparently they tried to get product description as if it were a dropdown type attribute (dropdown, multiple select, ...), but obviously it's not.

Disabling everything related to description in this module solved the issue for me.

answered Sep 2, 2024 at 8:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.