Php array_map with static object method

I want to use array_map with a static method, but I fail. Here is my code:

Class Buy { public function payAllBills() { $bill_list = OtherClass::getBillList(); return array_map(array(self, 'pay'), $bill_list); // Issue line } private static function pay($bill) { // Some stuff return true; } } 

PHP gives me an error:

 Use of undefined constant self - assumed 'self' 

I also tried:

 return array_map('self::makeBean()', $model_list); 

But that will not work.

Do you have any idea on how to use array_map with a static method?

I already read: Can a method be used as an array_map function in PHP 5.2? , but this question is about standard methods, not statics.

+5
source share
1 answer

According to the documentation ,

 return array_map('self::pay', $model_list); 

Note that your attempt to include () in a method name string that would be incorrect

+14
source

Source: https://habr.com/ru/post/1241472/


All Articles