PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] How to remove silencing errors is descouraged error from magento 2?

 August 23, 2022     magento, magento2, php, phpcs, xpath     No comments   

Issue

I have written code for SSO in magento 2.3 and for handling response from differnt IDPs like okta, keycloak I have done following code:

 if(!(@$xpath->query('/saml2p:Response',$xml))) {

            $status = SAML2Utilities::xpQuery($xml, './samlp:Status/samlp:StatusCode');   
}
        else{

           $status = SAML2Utilities::xpQuery($xml, './saml2p:Status/saml2p:StatusCode');   
}

My code is working fine, I can login through different IDPs, but when I checked php coding standard for magento 2 I am getting following error: 'Silencing errors is discouraged; found: @$xpath->query... ' How to resolve this?


Solution

In PHP errors can be silenced by using @ operator. On your code you have:

if(!(@$xpath->query('/saml2p:Response',$xml))) {

so you have a @ before $xpath->query. If you remove @ the error will not be displayed when you will check for coding standards.

For more information regarding hiding errors you can check the PHP Documentation

UPDATE:

Removing @ may cause problems as if an error happens it will stop code execution. You either need to handle the errors with a try catch or make check such as check if variable is null, empty etc.



Answered By - Zenel Rrushi
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,206,945

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing