Tag Archives: singleton

PHP Factory & Singleton

A friend sent me an ICQ today asking an easy way to load classes on the fly, but keep a registry of them to save resources if he calls said object more than once per page load. Here is the quick example I gave him:
123456789101112131415161718192021<?php
class loader {
    static $storage;
 
    public function factory($name) {
  [...]