将字符串转换为对象时遇到问题。这是功能:
public function slikepoid($dire,$id)
{
$this->dire=$dire;
$this->id=$id;
$slike = $this->skupljanjeslika($this->dire);
$slikeid = array_filter($slike, function($el) {
return substr( $el, 0, 2) == '$this->id-'; // Here is the problem !
});
return $slikeid;
}
我收到了这个错误:
致命错误:在第 8 行不在对象上下文中时使用 $this
我试过了:
return substr( $el, 0, 2) == ''.(string)$this->id;'-';
但没有运气:(