magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Error Deprecated Functionality plugin magento zendframework1

Open mohammedTBB opened this issue 4 years ago • 19 comments

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.
  • [X] 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”.

mohammedTBB avatar Sep 01 '22 10:09 mohammedTBB

Hi @mohammedTBB. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Sep 01 '22 10:09 m2-assistant[bot]

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
      DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
    1. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

m2-assistant[bot] avatar Sep 01 '22 11:09 m2-assistant[bot]

Hi @mohammedTBB ,

We are trying to reproduce the issue in 2.4.5 magento instance....But we are not able to reproduce the issue. We are getting expected result and it is not reproducible.

Steps: 1.install 2.4.5 magento instance 2.Go to category page 3.Select the product 4.got to product page 5.No error occurring

Let us know if we missing anything!

Thanks!!!

engcom-Dash avatar Sep 01 '22 11:09 engcom-Dash

Maybe the Anowave E-commerce 3rd party package script (i.e. CrashReporter.php) detects an issue that triggers a call to Zend/DbStatement.php... which in turn then executes the deprecated functionality in M2 zendframework? Perhaps wouldn't be reproduceable unless Anowave EC extension tries to report the "crash". We've had a several of that kind of circumstance in debugging php8.1 compatibility issues in 3rd party extensions: fix the first bit of deprecated code, test and that reveals a new one downstream... rinse and repeat.

image

n2diving-net avatar Sep 01 '22 12:09 n2diving-net

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Sep 05 '22 07:09 m2-assistant[bot]

Hello @mohammedTBB,

Thanks for the report and collaboration!

We have checked this issue in the Magento 2.4.5, 2.4.4, and 2.4-develop branches. And also examine the file vendor/magento/zendframework1/library/Zend/Db/Statement.php and found that the suggested possible fix as below:

if ($sql === null) {
           return '';
}

is already there in line no. 201.

https://github.com/magento/zf1/blob/2381396d2a9a528be2f367b5ce2dddf650eac1d0/library/Zend/Db/Statement.php#L201

Hello @n2diving-dgx,

Can you please suggest a way to reproduce the issue? Does we need to install the Anowave E-commerce, and the try to throw an issue. Please suggest.

Thanks

engcom-Hotel avatar Sep 05 '22 08:09 engcom-Hotel

@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?

hostep avatar Sep 05 '22 09:09 hostep

Hello @engcom-Hotel

yes there is check in line 201 but then the value of $sql changed.

what worked for us is adding the check at line 222

image

to reproduce the error it is essential to have the plugin amasty google rich snippets, knowing that disabling this plugin the error is no longer showing.

what seems to happen that the plugin amasty google rich snippets calls a zendfremwork funcion where the error happen.

mohammedTBB avatar Sep 05 '22 09:09 mohammedTBB

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

engcom-Hotel avatar Sep 06 '22 06:09 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6632 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Sep 06 '22 06:09 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Sep 06 '22 06:09 m2-assistant[bot]

@mohammedTBB @hostep @n2diving-dgx does anyone of you know how to reproduce this issue? From what I can read, it does not always occur? I have the same situation for a client.

Aquive avatar Nov 25 '22 13:11 Aquive

@Aquive: try outputting/debugging what the $sql variable contains just before this and this line. That might reveal why preg_replace runs into an error in your case.

Feel free to report back here, it will most likely make it easier to understand for the people involved here how it can happen.

hostep avatar Nov 25 '22 22:11 hostep

@hostep the error sometimes occurs on production. But the problem for me is that I don't know how to reproduce this locally.

Any ideas?

Aquive avatar Dec 02 '22 11:12 Aquive

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.

hostep avatar Jan 02 '23 14:01 hostep

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)

joshbourke avatar Jan 18 '23 20:01 joshbourke

I hit the same issue but on a different case. I have magento 2.4.5. When trying to rollback my database I got this: Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/xxxxxxx/vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222

This breaks the rollback of the database so I think is critical. At the moment I cannot restore my database! Any suggestions?

cptX avatar Mar 04 '23 06:03 cptX

Hello @mohammedTBB,

The issue is still relevant, tried the steps mentioned in this https://github.com/magento/magento2/issues/36069#issuecomment-1387714639, but it seems the issue does not belong to this repo.

It should be created in https://github.com/magento/magento-zend-db repo. After checking found a similar issue here in that repo:

https://github.com/magento/magento-zend-db/issues/2

I think we can close this issue from here.

engcom-Hotel avatar Oct 09 '24 10:10 engcom-Hotel

Hi @engcom-Hotel thanks for trying to reproduce the error and for this information.

mohammedTBB avatar Oct 09 '24 11:10 mohammedTBB