Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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