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:
-
Where is preg_replace in the code you provided?elfling– elfling2023年01月10日 11:08:51 +00:00Commented 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, EdwinEdwin– Edwin2023年02月06日 21:12:59 +00:00Commented Feb 6, 2023 at 21:12
3 Answers 3
Update below line :
$specs = trim( str_replace( array("\r\n","\r", "" ),"", $specs ) );
to
if($specs){
$specs = trim( str_replace( array("\r\n","\r", "" ),"", $specs ) );
}
-
-
As per your error message, Your 3rd parameter is NULL in str_replace.Dhaval Vaghela– Dhaval Vaghela2023年01月08日 10:57:54 +00:00Commented Jan 8, 2023 at 10:57
-
I added a screenshoot of outputGkna– Gkna2023年01月12日 20:45:51 +00:00Commented Jan 12, 2023 at 20:45
-
@Gkna how to fix thisUser0434– User04342023年01月18日 14:06:47 +00:00Commented Jan 18, 2023 at 14:06
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
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.