Annotation of embedaddon/php/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Testing ReflectionClass::isCloneable()
3: --SKIPIF--
4: <?php if (!extension_loaded('simplexml') || !extension_loaded('xmlwriter')) die("skip SimpleXML and XMLWriter is required for this test"); ?>
5: --FILE--
6: <?php
7:
8: class foo {
9: }
10: $foo = new foo;
11:
12: print "User class\n";
13: $obj = new ReflectionClass($foo);
14: var_dump($obj->isCloneable());
15: $obj = new ReflectionObject($foo);
16: var_dump($obj->isCloneable());
17: $h = clone $foo;
18:
19: class bar {
20: private function __clone() {
21: }
22: }
23: $bar = new bar;
24: print "User class - private __clone\n";
25: $obj = new ReflectionClass($bar);
26: var_dump($obj->isCloneable());
27: $obj = new ReflectionObject($bar);
28: var_dump($obj->isCloneable());
29: $h = clone $foo;
30:
31: print "Closure\n";
32: $closure = function () { };
33: $obj = new ReflectionClass($closure);
34: var_dump($obj->isCloneable());
35: $obj = new ReflectionObject($closure);
36: var_dump($obj->isCloneable());
37: $h = clone $closure;
38:
39: print "Internal class - SimpleXMLElement\n";
40: $obj = new ReflectionClass('simplexmlelement');
41: var_dump($obj->isCloneable());
42: $obj = new ReflectionObject(new simplexmlelement('<test></test>'));
43: var_dump($obj->isCloneable());
44: $h = clone new simplexmlelement('<test></test>');
45:
46: print "Internal class - XMLWriter\n";
47: $obj = new ReflectionClass('xmlwriter');
48: var_dump($obj->isCloneable());
49: $obj = new ReflectionObject(new XMLWriter);
50: var_dump($obj->isCloneable());
51: $h = clone new xmlwriter;
52:
53: ?>
54: --EXPECTF--
55: User class
56: bool(true)
57: bool(true)
58: User class - private __clone
59: bool(false)
60: bool(false)
61: Closure
62: bool(true)
63: bool(true)
64: Internal class - SimpleXMLElement
65: bool(true)
66: bool(true)
67: Internal class - XMLWriter
68: bool(false)
69: bool(false)
70:
71: Fatal error: Trying to clone an uncloneable object of class XMLWriter in %s on line %d
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>