singleton fix visible __wakeup()

1) DesignPatterns\Creational\Singleton\Tests\SingletonTest::testUniqueness
The magic method DesignPatterns\Creational\Singleton\Singleton::__wakeup() must have public visibility

/app/Creational/Singleton/Singleton.php:39
/app/Creational/Singleton/Tests/SingletonTest.php:12

ERRORS!
This commit is contained in:
Roman Martinuk
2021-03-14 20:58:23 +03:00
parent 1b6df79fc5
commit 74c96851d1

View File

@@ -2,6 +2,8 @@
namespace DesignPatterns\Creational\Singleton; namespace DesignPatterns\Creational\Singleton;
use Exception;
final class Singleton final class Singleton
{ {
private static ?Singleton $instance = null; private static ?Singleton $instance = null;
@@ -36,7 +38,8 @@ final class Singleton
/** /**
* prevent from being unserialized (which would create a second instance of it) * prevent from being unserialized (which would create a second instance of it)
*/ */
private function __wakeup() public function __wakeup()
{ {
throw new Exception("Cannot unserialize singleton");
} }
} }