<?php class ColorChanger { public $lastColors = []; public function blackMethod() { $colors = implode(', ', $this->lastColors); echo "blackMethod(); Last colors: {$colors}\n"; $this->lastColors[] = 'black'; return $this; } public function whiteMethod() { $colors = implode(', ', $this->lastColors); echo "whiteMethod(); Last colors: {$colors}\n"; $this->lastColors[] = 'white'; return $this; } public function colourMethod() { $colors = implode(', ', $this->lastColors); $lastColor = $this->lastColors[count($this->lastColors)-1]; echo "colourMethod(): {$colors} (Last: $lastColor)\n"; $this->lastColors = []; } } $c = new ColorChanger(); $c->blackMethod()->colourMethod(); $c->whiteMethod()->colourMethod(); $c->blackMethod()->whiteMethod()->blackMethod()->colourMethod();
You have javascript disabled. You will not be able to edit any code.