1
edit
Changes
→Sample Code
}
}
</pre>
Singleton pattern in PHP 5:
<pre>
<?php
class Singleton {
// object instance
static $instance;
private function __construct() {}
private function __clone() {}
public static function getInstance() {
if (!Singleton::$instance instanceof self) {
Singleton::$instance = new self();
}
return Singleton::$instance;
}
}
?>
</pre>