How to use $this in closure in php
$this
is always available in (non-static) closures since PHP 5.4, no need to use
it.
class Service {
function delete_user($username) {
...
$sessions = $this->config->sessions;
$this->config->sessions = array_filter($sessions, function($session) {
return $this->get_username($session->token) != $username;
});
}
}
See PHP manual - Anonymous functions - Automatic binding of $this