3v4l.org

run code in 300+ PHP versions simultaneously
<?php class C{ protected $date; public function __construct(){ $this->date=new DateTime(); } public function getCurrent(){ return clone $date; } } class A extends C{ public function getDate(){ return $this->getCurrent()->add(new DateInterval('P10D')); } public function getDateAgain(){ return $this->getCurrent()->add(new DateInterval('P10D')); } } class B extends C{ public function getDate(){ return $this->getCurrent()->add(new DateInterval('P20D')); } } $a=new A(); $b=new B(); echo $a->getDate()->format('Y-m-d') . "\n"; echo $b->getDate()->format('Y-m-d') . "\n"; echo $a->getDateAgain()->format('Y-m-d') . "\n";
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $date in /in/MYNp6 on line 11 Fatal error: Uncaught Error: __clone method called on non-object in /in/MYNp6:11 Stack trace: #0 /in/MYNp6(16): C->getCurrent() #1 /in/MYNp6(30): A->getDate() #2 {main} thrown in /in/MYNp6 on line 11
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
31.91 ms | 401 KiB | 8 Q