December 2016
Beginner to intermediate
238 pages
6h 10m
English
© Kelt Dockins 2017
Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_7
Kelt Dockins1
(1)Dolph, Arkansas, USA
$> git checkout singletonEnsure a class only has one instance and provide a global point of access to it.1
Short answer: none. Honestly, I have yet to find any practical applications for the singleton pattern in PHP. The original singleton design pattern was made to ensure that only one instance of a class could ever be created. It was used in the context of printer spoolers where you would only ever want one instance created. Out of the box, PHP is a single-threaded environment and usually has a short lifetime within an apache/nginx thread. Even if you used something like React ...
Read now
Unlock full access