ReflectionClass_isCloneable_001.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. class foo {
  8. }
  9. $foo = new foo;
  10. print "User class\n";
  11. $obj = new ReflectionClass($foo);
  12. var_dump($obj->isCloneable());
  13. $obj = new ReflectionObject($foo);
  14. var_dump($obj->isCloneable());
  15. $h = clone $foo;
  16. class bar {
  17. private function __clone() {
  18. }
  19. }
  20. $bar = new bar;
  21. print "User class - private __clone\n";
  22. $obj = new ReflectionClass($bar);
  23. var_dump($obj->isCloneable());
  24. $obj = new ReflectionObject($bar);
  25. var_dump($obj->isCloneable());
  26. $h = clone $foo;
  27. print "Closure\n";
  28. $closure = function () { };
  29. $obj = new ReflectionClass($closure);
  30. var_dump($obj->isCloneable());
  31. $obj = new ReflectionObject($closure);
  32. var_dump($obj->isCloneable());
  33. $h = clone $closure;
  34. print "Internal class - SimpleXMLElement\n";
  35. $obj = new ReflectionClass('simplexmlelement');
  36. var_dump($obj->isCloneable());
  37. $obj = new ReflectionObject(new simplexmlelement('<test></test>'));
  38. var_dump($obj->isCloneable());
  39. $h = clone new simplexmlelement('<test></test>');
  40. print "Internal class - XMLWriter\n";
  41. $obj = new ReflectionClass('xmlwriter');
  42. var_dump($obj->isCloneable());
  43. $obj = new ReflectionObject(new XMLWriter);
  44. var_dump($obj->isCloneable());
  45. $h = clone new xmlwriter;
  46. ?>
  47. --EXPECTF--
  48. User class
  49. bool(true)
  50. bool(true)
  51. User class - private __clone
  52. bool(false)
  53. bool(false)
  54. Closure
  55. bool(true)
  56. bool(true)
  57. Internal class - SimpleXMLElement
  58. bool(true)
  59. bool(true)
  60. Internal class - XMLWriter
  61. bool(false)
  62. bool(false)
  63. Fatal error: Trying to clone an uncloneable object of class XMLWriter in %s on line %d