summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2007-11-23 13:25:21 +0000
committerMarcus Boerger <helly@php.net>2007-11-23 13:25:21 +0000
commitc0802ee667cb0308c44515a80f6a36b8c1c6ef48 (patch)
treea354f39e7e1cf2a3e2d84ff292b8c8fe78710198 /Zend
parent543f24742bbf0e693a5402c4d966558206bc3a4c (diff)
downloadphp-git-c0802ee667cb0308c44515a80f6a36b8c1c6ef48.tar.gz
- Add another LSB test
Diffstat (limited to 'Zend')
-rwxr-xr-xZend/tests/lsb_018.phpt95
1 files changed, 95 insertions, 0 deletions
diff --git a/Zend/tests/lsb_018.phpt b/Zend/tests/lsb_018.phpt
new file mode 100755
index 0000000000..5a678d1853
--- /dev/null
+++ b/Zend/tests/lsb_018.phpt
@@ -0,0 +1,95 @@
+--TEST--
+ZE2 Late Static Binding and Singleton
+--FILE--
+<?php
+abstract class Singleton
+{
+ static private $instances = array();
+ static private $nextInstanceId = 0;
+ private $instanceId = NULL;
+ static final public function getInstance()
+ {
+ $caller = get_called_class();
+ if (!isset(self::$instances[$caller])) {
+ self::$instances[$caller] = new $caller;
+ self::$instances[$caller]->instanceId = self::$nextInstanceId++;
+ }
+ return self::$instances[$caller];
+ }
+ public final function getInstanceId()
+ {
+ return $this->instanceId;
+ }
+ public final function identify()
+ {
+ var_dump($this);
+ }
+}
+
+class Foo extends Singleton {
+}
+
+class Bar extends Singleton {
+}
+
+class Baz extends Bar {
+}
+
+$u = Foo::getInstance();
+$v = Bar::getInstance();
+$w = Baz::getInstance();
+
+$u->identify();
+$v->identify();
+$w->identify();
+
+$x = Foo::getInstance();
+$y = Bar::getInstance();
+$z = Baz::getInstance();
+
+$u->identify();
+$v->identify();
+$w->identify();
+$x->identify();
+$y->identify();
+$z->identify();
+?>
+===DONE===
+--EXPECTF--
+object(Foo)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(0)
+}
+object(Bar)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(1)
+}
+object(Baz)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(2)
+}
+object(Foo)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(0)
+}
+object(Bar)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(1)
+}
+object(Baz)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(2)
+}
+object(Foo)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(0)
+}
+object(Bar)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(1)
+}
+object(Baz)#%d (1) {
+ ["instanceId":"Singleton":private]=>
+ int(2)
+}
+===DONE===