jeffturcotte
3/21/2014 - 6:12 PM

Trait Usage

Trait Usage

<?php
class Word {}
class NotAWord { }

trait SayTrait {
	function say(Word $word) {
		echo 'word?';
	}
}

class Speaker {
	use SayTrait;	

	function say(NotAWord $notAWord) {
		echo 'whaaaa!';
	}
}

$speaker  = new Speaker();
$notAWord = new NotAWord();

$speaker->say($notAWord);