Skip to content

Instantly share code, notes, and snippets.

@jeffturcotte
Created March 21, 2014 18:12
Show Gist options
  • Save jeffturcotte/9692230 to your computer and use it in GitHub Desktop.
Save jeffturcotte/9692230 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment