ReflectionClass_isCloneable_001.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. Testing ReflectionClass::isCloneable()
  3. --EXTENSIONS--
  4. simplexml
  5. xmlwriter
  6. --FILE--
  7. <?php
  8. class foo {
  9. }
  10. $foo = new foo;
  11. print "User class\n";
  12. $obj = new ReflectionClass($foo);
  13. var_dump($obj->isCloneable());
  14. $obj = new ReflectionObject($foo);
  15. var_dump($obj->isCloneable());
  16. $h = clone $foo;
  17. class bar {
  18. private function __clone() {
  19. }
  20. }
  21. $bar = new bar;
  22. print "User class - private __clone\n";
  23. $obj = new ReflectionClass($bar);
  24. var_dump($obj->isCloneable());
  25. $obj = new ReflectionObject($bar);
  26. var_dump($obj->isCloneable());
  27. $h = clone $foo;
  28. print "Closure\n";
  29. $closure = function () { };
  30. $obj = new ReflectionClass($closure);
  31. var_dump($obj->isCloneable());
  32. $obj = new ReflectionObject($closure);
  33. var_dump($obj->isCloneable());
  34. $h = clone $closure;
  35. print "Internal class - SimpleXMLElement\n";
  36. $obj = new ReflectionClass('simplexmlelement');
  37. var_dump($obj->isCloneable());
  38. $obj = new ReflectionObject(new simplexmlelement('<test></test>'));
  39. var_dump($obj->isCloneable());
  40. $h = clone new simplexmlelement('<test></test>');
  41. print "Internal class - XMLWriter\n";
  42. $obj = new ReflectionClass('xmlwriter');
  43. var_dump($obj->isCloneable());
  44. $obj = new ReflectionObject(new XMLWriter);
  45. var_dump($obj->isCloneable());
  46. $h = clone new xmlwriter;
  47. ?>
  48. --EXPECTF--
  49. User class
  50. bool(true)
  51. bool(true)
  52. User class - private __clone
  53. bool(false)
  54. bool(false)
  55. Closure
  56. bool(true)
  57. bool(true)
  58. Internal class - SimpleXMLElement
  59. bool(true)
  60. bool(true)
  61. Internal class - XMLWriter
  62. bool(false)
  63. bool(false)
  64. Fatal error: Uncaught Error: Trying to clone an uncloneable object of class XMLWriter in %s:%d
  65. Stack trace:
  66. #0 {main}
  67. thrown in %s on line %d