0

I have some one question for this code

self::$connect = @new PDO(
            "mysql:host=$host;dbname=$databes",
            $user,
            $password,
            self::$setting
        );

What exactly does the @ symbol in front of new mean?

I try to find in the manuals why @ is written when creating a PDO and I still can't find the answer.

Very thanks for answer.

  • 1
    [error control operator](https://www.php.net/manual/en/language.operators.errorcontrol.php) – Remy Feb 27 '22 at 12:40
  • This would help https://stackoverflow.com/a/9835960/17788846 – Emma Marshall Feb 27 '22 at 12:40
  • 2
    It suppresses errors and should be avoided when ever possible. It's really bad practice to have those. Hiding errors makes debugging a real pain. In this case, make PDO throw exceptions on errors and handle the exceptions in your application properly instead. – M. Eriksson Feb 27 '22 at 12:47
  • The most stupid thing that ever can be done – Your Common Sense Feb 27 '22 at 13:01
  • *Also* `self::$connect` is not overly smart move too. – Your Common Sense Feb 27 '22 at 13:02
  • It means that whoever wrote the code you're reusing didn't care about managing errors and exceptions. While `@` is technically called _error control operator_, it's usually read as **"Steer clear of this code or spend your eternity chased by ghosts"** by coders of experience. You know, `@ @ @ . . .` <-- these are the guys chasing `. . (<` PacMan since the ancient of days. – Markus AO Feb 27 '22 at 15:23

0 Answers0