I used following code

->order(new \Zend_Db_Expr('FIELD(option_id,' . implode(',', $totalPro).')'));

That give following warning.

Direct object instantiation (object of \Zend_Db_Expr) is discouraged in Magento 2.

How to remove this warning?

  • Have you tested: ->order(\Zend_Db_Expr('FIELD(option_id,' . implode(',', $totalPro).')')); Magento doesn't use new \Class\Name instead of that they have implemented an object manager.
    – DavidVR
    Apr 12, 2018 at 16:00
  • @DavidVR already tried Fatal error: Uncaught Error: Call to undefined function Zend_Db_Expr() Apr 12, 2018 at 16:05
  • @QaisarSatti try first store value in a variable and then use a variable in query. Check this core file: vendor/magento/module-review/Model/ResourceModel/Rating.php Apr 12, 2018 at 16:54
  • @PrincePatel magento 2 is using Zend_Db_Expr but got the same error on core file not allowed. Apr 12, 2018 at 17:09

1 Answer 1


Please use this :


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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