OOP PHP rozprávka class Yogi extends Bear { public $hasBasket; public $rangerVisible; public function __construct() { parent::__construct('Yogi'); $this->hasBasket = false; $this->rangerVisible = true; } public function act() { if($this->hasBasket) { while($this->rangerVisible === true) { $this->run(); } $this->eat('Basket'); } else { if($this->rangerVisible === false) { $this->shit(); } $this->searchBasket(); } } private function run() { if(rand(0, 2) == 1) { $this->rangerVisible = false; } } private function searchBasket() { if(rand(0, 10) == 1) { $this->hasBasket = true; } } } // end class Yogi class Bear { private $name; private $stomach; public function __construct($name) { $this->name = &$name; $this->stomach = array(); } protected function eat($what) { $this->stomach[] = &$what; } protected function shit() { array_shift($this->stomach); } protected function spew() { array_pop($this->stomach); } } // end class Bear