Created
July 23, 2011 19:24
-
-
Save laszlokorte/1101779 to your computer and use it in GitHub Desktop.
Is this possible in php 5.4 with the new traits feature?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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