【发布时间】:2017-11-12 21:51:05
【问题描述】:
我有这样的功能:
class Service {
function delete_user($username) {
...
$sessions = $this->config->sessions;
$this->config->sessions = array_filter($sessions, function($session) use ($this){
return $this->get_username($session->token) != $username;
});
}
}
但这不起作用,因为您不能在use 中使用$this,是否可以在回调中执行属于Service 类成员的函数?还是我需要使用 for 或 foreach 循环?
【问题讨论】:
标签: php closures this anonymous-function