Skip to content

Instantly share code, notes, and snippets.

@revathskumar
Created August 12, 2015 05:04
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 revathskumar/c228e0b4a4da514048f7 to your computer and use it in GitHub Desktop.
Save revathskumar/c228e0b4a4da514048f7 to your computer and use it in GitHub Desktop.
<?php
Class Api {
public static $log;
public static function setLogger($func) {
self::$log = &$func;
}
public static function errorLog($st) {
$func = &self::$log;
$func($st);
}
public function doSth() {
self::errorLog('In doSth');
}
}
Class Logger {
public static function log($statement) {
printf("%s \r\n", $statement);
}
}
Api::setLogger(function($statement){
Logger::log($statement);
});
Api::errorLog('Hello world');
Api::errorLog('This function is set later');
$api = new Api;
$api->doSth();
//Api::$log = function ($st) {
// print $st;
//};
//Api::$log('Hello');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment