title: Singleton pattern in PHP 8.0 and private magic methods
body: <p>I am using a <a href="https://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow noreferrer">singleton</a> class in PHP according to the following pattern:</p>
  <pre><code>class MY_Singleton
  {
      public static function instance()
      {
        static $instance = false;
        if( $instance === false )
        {
          // Late static binding (PHP 5.3+)
          $instance = new static();
        }
  
        return $instance;
      }
  
      /**
       * Make constructor private, so nobody can call &quot;new Class&quot;.
       */
      private function __construct() {}
  
      /**
       * Make clone magic method private, so nobody can clone instance.
       */
      private function __clone() {}
  
      /**
       * Make sleep magic method private, so nobody can serialize instance.
       */
      private function __sleep() {}
  
      /**
       * Make wakeup magic method private, so nobody can unserialize instance.
       */
      private function __wakeup() {}
  
  }
  </code></pre>
  <p>This used to work just fine under PHP 7.X.X. Now, under PHP 8.0 I am getting warnings such as:</p>
  <pre><code>Warning: The magic method My_Singleton::__wakeup() must have public visibility in [...]
  </code></pre>
  <p>Should I implement a singleton differently under PHP 8.0? Or should I just turn off these warnings? If so, how do I do this in a way that is backward compatible with PHP 7.X.X?</p>