3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class ObjectOne { protected $someParam = 'foo'; protected $someOtherParam = 'bar'; protected $saveMe = NULL; protected function update() { $this->someParam = 'FOO'; $this->someOtherParam = 'BAR'; return true; } protected function revert(){ $this->someParam = $this->saveMe->someParam; $this->someOtherParam = $this->saveMe->someOtherParam; $this->saveMe = NULL; } } Class ObjectTwo extends ObjectOne { protected $someParam = 'faa'; protected $someOtherParam = 'bor'; public function update() { $this->saveMe = $this; if(parent::update()) { $this->someParam = 'poo'; if($this->someParam === 'foo') { return true; } else { $this->revert(); parent::update(); return false; } } else { return false; } } } $testOb = new ObjectTwo(); print_r($testOb->update());

preferences:
36.15 ms | 402 KiB | 5 Q