The classic singleton implementation. PHP example open

The classic singleton implementation. PHP example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
class Cookie{
	public static int $baseTime = 86400 * 7;
	public static string $basePath = '/';
	protected static $instance;

//set protected for our constructor. This will not allow instances of our class to be created!
	protected function __construct(){}

// write a method that will create an instance of our class
// before creating a new object, check whether another class object has already been created
	public static function getInstance() : self{
		if(self::$instance === null){
			self::$instance = new self();
		}

		return self::$instance;
	}

	public function get(string $name) : ?string{
		return $_COOKIE[$name] ?? null;
	}
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation