PHP closure as static class variable
问题 I wanted to have a static closure variable in my class, so that people can change the behavior of a specific part of the code. However, I can't seem to be able to initialize it anywhere. First I tried this: public static $logger = function($sql) { print_r($sql); }; But apparently PHP can't handle that. Ok, so I made a static init method: public static $logger; static function init() { /* if (!Base::logger) */ Base::logger = function($sql) { print_r($sql); }; } And call it at the end of the