cvs: ZendEngine2 /tests lsb_018.phpt
| From: | Marcus Boerger | Date: | Fri, 23 Nov 2007 13:25:35 +0000 |
| Subject: | cvs: ZendEngine2 /tests lsb_018.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-6209@lists.php.net to get a copy of this message | ||
helly Fri Nov 23 13:25:35 2007 UTC
Modified files:
/ZendEngine2/tests lsb_018.phpt
Log:
- Add another LSB test
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/lsb_018.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/lsb_018.phpt
diff -u /dev/null ZendEngine2/tests/lsb_018.phpt:1.2
--- /dev/null Fri Nov 23 13:25:35 2007
+++ ZendEngine2/tests/lsb_018.phpt Fri Nov 23 13:25:35 2007
@@ -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===