Last active
November 5, 2022 05:20
-
-
Save arnissolle/507352525655a336c9e9ed04225397bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| trait Singleton | |
| { | |
| private static $instance; | |
| public static function getInstance(...$args): static | |
| { | |
| if (null === self::$instance) { | |
| self::$instance = new static(...$args); | |
| } | |
| return self::$instance; | |
| } | |
| } | |
| class Foo | |
| { | |
| use Singleton; | |
| private function __construct( | |
| private int $id | |
| ) {} | |
| public function bar(): string | |
| { | |
| return "FooBar: {$this->id}"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.