Skip to content

Instantly share code, notes, and snippets.

@laszlokorte
Created July 23, 2011 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laszlokorte/1101779 to your computer and use it in GitHub Desktop.
Save laszlokorte/1101779 to your computer and use it in GitHub Desktop.
Is this possible in php 5.4 with the new traits feature?
<?php
/**
* Is this possible in php5.4 using traits?
*/
trait Hashmap {
public function set($key, $val) {
$this->data[$key] = $val;
}
public function get($key) {
return $this->data[$key];
}
}
trait HashLogger {
public function log($msg) {
// ...
}
public function set($key, $val) {
$this->log("{$key} has been set to {$val}");
parent::set($key, $val);
}
}
class Config {
use HashMap;
use HashLogger;
public function set($key, $val) {
parent::set($key, $val);
$this->clearCache();
}
protected function clearCache() {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment