PHP code example of ap-lib / singleton
1. Go to this page and download the library: Download ap-lib/singleton 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/ */
ap-lib / singleton example snippets
use AP\Singleton\Singleton;
class Hello
{
use Singleton;
private string $format;
public function sayHello(string $name): string
{
return sprintf($this->format, $name);
}
private function __construct()
{
$this->format = "Hello %s";
}
}
echo Hello::getInstance()->sayHello("World"); // Hello World