Last active
February 21, 2017 08:49
-
-
Save garveen/d9045669e5eb25916036fd30cf418cf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Base | |
{ | |
private $called = false; | |
public function save() | |
{ | |
if ($this->called) { | |
throw new Exception("should be only called once!", 1); | |
} | |
$this->called = true; | |
} | |
} | |
trait TraitA | |
{ | |
public function save() | |
{ | |
parent::save(); | |
} | |
} | |
trait TraitB | |
{ | |
public function save() | |
{ | |
parent::save(); | |
} | |
} | |
class ExtA extends Base | |
{ | |
use TraitA; | |
} | |
class ExtB extends Base | |
{ | |
use TraitB; | |
} | |
class ExtC extends Base | |
{ | |
use TraitA, TraitB { | |
TraitA::save as saveA; | |
TraitB::save as saveB; | |
} | |
function save() | |
{ | |
$this->saveA(); | |
$this->saveB(); | |
} | |
} | |
$a = new ExtA; | |
$a->save(); | |
$b = new ExtB; | |
$b->save(); | |
$c = new ExtC; | |
$c->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment