magento2: Error Deprecated Functionality plugin magento zendframework1

Preconditions and environment

  • Magento v2.4.5
  • php v8.1

Steps to reproduce

1- Go to category page 2- Choose a product and go to product page (not all products)

Expected result

No error

Actual result

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

#1 call_user_func_array() called at [app/code/Anowave/Ec/vendor/FacebookAds/CrashReporter.php:154]
#2 Anowave\Ec\vendor\FacebookAds\CrashReporter->Anowave\Ec\vendor\FacebookAds\{closure}()
#3 preg_replace() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:222]
#4 Zend_Db_Statement->_stripQuoted() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:139]
#5 Zend_Db_Statement->_parseParameters() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:114]
#6 Zend_Db_Statement->__construct() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:184]
#7 Zend_Db_Adapter_Pdo_Abstract->prepare() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:479]
#8 Zend_Db_Adapter_Abstract->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:238]
#9 Zend_Db_Adapter_Pdo_Abstract->query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:564]
#10 Magento\Framework\DB\Adapter\Pdo\Mysql->_query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:634]
#11 Magento\Framework\DB\Adapter\Pdo\Mysql->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:737]
#12 Zend_Db_Adapter_Abstract->fetchAll() called at [vendor/magento/framework/Data/Collection/Db/FetchStrategy/Query.php:21]
#13 Magento\Framework\Data\Collection\Db\FetchStrategy\Query->fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:782]
#14 Magento\Framework\Data\Collection\AbstractDb->_fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:677]
#15 Magento\Framework\Data\Collection\AbstractDb->getData() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:580]
#16 Magento\Framework\Data\Collection\AbstractDb->loadWithFilter() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:565]
#17 Magento\Framework\Data\Collection\AbstractDb->load() called at [vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php:123]
#18 Magento\Eav\Model\Entity\Attribute\Source\Table->getSpecificOptions() called at [vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php:157]
#19 Magento\Eav\Model\Entity\Attribute\Source\Table->getOptionText() called at [vendor/magento/module-catalog/Model/Product.php:1807]
#20 Magento\Catalog\Model\Product->getAttributeText() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:427]
#21 Amasty\SeoRichData\Block\Product->updateCustomProperties() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:327]
#22 Amasty\SeoRichData\Block\Product->generateOffers() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:210]
#23 Amasty\SeoRichData\Block\Product->prepareOffers() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:150]
#24 Amasty\SeoRichData\Block\Product->getResultArray() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:133]
#25 Amasty\SeoRichData\Block\Product->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1095]
#26 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1099]
#27 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:660]
#28 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:578]
#29 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:555]
#30 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#31 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#32 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#33 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#34 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#35 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#36 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#37 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#38 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#39 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#40 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:975]
#41 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#42 Magento\Framework\View\Layout\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#43 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#44 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:41]
#45 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:260]
#46 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171]
#47 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#48 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#49 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#50 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:32]
#51 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120]
#52 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#53 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]

Additional information

Possible solution:

diff --git a/vendor/magento/zendframework1/library/Zend/Db/Statement.php b/vendor/magento/zendframework1/library/Zend/Db/Statement.php
index 46d175c..60c77a9 100644
--- a/vendor/magento/zendframework1/library/Zend/Db/Statement.php
+++ b/vendor/magento/zendframework1/library/Zend/Db/Statement.php
@@ -209,6 +209,10 @@ abstract class Zend_Db_Statement implements Zend_Db_Statement_Interface
         // remove "foo\"bar"
         $sql = preg_replace("/\"(\\\\\"|[^\"])*\"/Us", '', $sql);
 
+        if ($sql === null) {
+            return '';
+        }
+
         // get the character for delimited id quotes,
         // this is usually " but in MySQL is `
         $d = $this->_adapter->quoteIdentifier('a');

Need to add this check after each preg_replace call i.e. 210 & 222. The simplest way to reproduce this issue is by setting $sql as null and then running bin/magento setup:upgrade command. The below error will occur: image

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@engcom-Hotel: if you read the error message carefully, you’ll see that the error happens on line 222. Which means that the check on line 201 already passed.

So this most likely means that the second preg_replace call failed, which would explain why the $sql value changes to null.

Also, we have a third preg_replace call, which could potentially also fail, so maybe that one needs to be checked as well?

The only thing I can think of, is to patch the code on production with some extra lines that try to detect this occurrence and add a bunch of logging to try to see what the $sql variable contains just before it turns into null… And then hope that after a few days you’ll find something interesting in your log files which can then hopefully explain what’s going on.

Hello @hostep @mohammedTBB,

Thanks for the reply!

I agree with your point @hostep, we need to add the checks after each preg_replace call here ie. line numbers i.e. 210 & 222.

I have also gone through the preg_replace documentation, it can be returned as null, in case of error occurred.

Hence confirming the issue.

Thanks

I stumbled across this recently. If you go to the Customer Grid in the admin and search: ':{}{}{":]a''a'a':{}{}{"a:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{}{":]a:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{"::]{":a'a':{}{}{":]a'']a''a'a':{}{}a'a':{}{}{":]a'']a''a'a':{}{}:{}{}{":]a'']a''a'a':{}{}}{":]a'']a''a'a':{}{}'']a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':':

You create an exception that stems from the same problem.

Note that you may hit a server error if the request URI is too long. You may need to adjust server config.

You have to be in production mode or have error reporting off because of a check done here: vendor/magento/framework/App/ErrorHandler.php:54

        $errorNo = $errorNo & error_reporting();
        if ($errorNo == 0) {
            return false;
        }

Exception:

[2023-01-18T19:42:07.045616+00:00] report.CRITICAL: Exception: Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /chroot/home/website/html/vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222 in /chroot/home/website/html/vendor/magento/framework/App/ErrorHandler.php:62
Stack trace:
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8192, 'preg_replace():...', '/chroot/home/mt...', 222)