Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2. // Without inheritance: words as expected
  3. class A {
  4.  
  5. public function x() {
  6. (new $this)->y();
  7. }
  8.  
  9. private function y() {
  10. echo "I occurred";
  11. }
  12. }
  13.  
  14. (new A())->x();
  15.  
  16. // Without inheritance: works as expected __clone
  17. class B {
  18.  
  19. public function x() {
  20. clone $this;
  21. }
  22.  
  23. private function __clone() {
  24. echo "I occurred";
  25. }
  26. }
  27.  
  28. (new B())->x();
  29.  
  30. // With inheritance: works as expected
  31. class C {
  32.  
  33. public function x() {
  34. (new $this)->y();
  35. }
  36.  
  37. private function y() {
  38. echo "I occurred";
  39. }
  40. }
  41.  
  42. class D extends C {}
  43.  
  44. (new D())->x();
  45.  
  46. // With inheritance: does not work as expected __clone
  47. class E {
  48.  
  49. public function x() {
  50. clone $this;
  51. }
  52.  
  53. private function __clone() {
  54. echo "I occurred";
  55. }
  56. }
  57.  
  58. class F extends E {}
  59.  
  60. (new F())->x();
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement