Skip to content

Instantly share code, notes, and snippets.

@geofmureithi-zz
Forked from wowo/traits.php
Created April 20, 2016 16:54
Show Gist options
  • Save geofmureithi-zz/28cb9675d76f70744c098fdb5d15fba3 to your computer and use it in GitHub Desktop.
Save geofmureithi-zz/28cb9675d76f70744c098fdb5d15fba3 to your computer and use it in GitHub Desktop.
<?php
trait Loggable {
public function log($event) {
printf("Event: '%s', source: '%s'\n",
event, get_class($this));
}
}
class User {
use Loggable;
public function something() {
$this->log("Something happened");
}
}
$u = new User;
$u->something();
// will echo:
// Event: 'Something happened', source: 'User'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment