PHP nested function gives 'Using $this when not in object context' error -


i trying filter array using built-in array_filter function. according examples in php manual, have provide name of callback function. so, here tried:

// function method  public function send($user_id, $access, $content, $aids) {     // check if user allowed see attachments     function is_owner($var)     {         return $this->attachment_owner($var, $user_id);     }      $aids = implode(';', array_filter(explode(';', $aids), 'is_owner')); } 

here error i'm getting:

fatal error: using $this when not in object context in filename line number.

how solve this?

since you're using php > 5.4.0, create anonymous function , use $this:

public function send($user_id, $access, $content, $aids) {        // check if user allowed see attachments     $is_owner = function ($var)     {         return $this->attachment_owner($var, $user_id);     }     $aids = implode(';', array_filter(explode(';', $aids), $is_owner)); 

nevertheless go tim's solution because cleaner.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -