Created
August 12, 2015 05:04
-
-
Save revathskumar/c228e0b4a4da514048f7 to your computer and use it in GitHub Desktop.
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 | |
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