📜 ⬆️ ⬇️

Implementing a Singleton design pattern for PHP 5.4

It would seem, of all the design patterns, what could be simpler than the well-known singleton. In many classical examples of implementation in different programming languages, it can take only a couple of dozen lines, and even less.

image It so happened that I have been implementing this template for the second year since the first release of PHP 5.3 in 2009. At that time, its predecessor, version 5.2, did not have late static binding, and in order to create an instance of a class, it was necessary to transfer its name to the method, which seemed archine-friendly to me.

With the release of PHP 5.4, having looked once again at the old implementation and at the new language features, I rewrote this pattern once again by getting - as it seemed to me then and it seems now - the final version.
')
Implementation details below.

I would like to immediately note the main features:

Source: https://habr.com/ru/post/157615/


All Articles