PHP code example of arunagirinathar / php-design-patterns
1. Go to this page and download the library: Download arunagirinathar/php-design-patterns library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
arunagirinathar / php-design-patterns example snippets
use Arunagirinathar\DesignPatterns\Singleton;
class MySingleton extends Singleton
{
private string $data = "Hello, Singleton!";
public function getData(): string
{
return $this->data;
}
}
$instance1 = MySingleton::getInstance();
$instance2 = MySingleton::getInstance();
echo $instance1->getData(); // Hello, Singleton!
var_dump($instance1 === $instance2); // true (Both refer to the same instance)