Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Without inheritance: words as expected
- class A {
- public function x() {
- (new $this)->y();
- }
- private function y() {
- echo "I occurred";
- }
- }
- (new A())->x();
- // Without inheritance: works as expected __clone
- class B {
- public function x() {
- clone $this;
- }
- private function __clone() {
- echo "I occurred";
- }
- }
- (new B())->x();
- // With inheritance: works as expected
- class C {
- public function x() {
- (new $this)->y();
- }
- private function y() {
- echo "I occurred";
- }
- }
- class D extends C {}
- (new D())->x();
- // With inheritance: does not work as expected __clone
- class E {
- public function x() {
- clone $this;
- }
- private function __clone() {
- echo "I occurred";
- }
- }
- class F extends E {}
- (new F())->x();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement