php array_map with static method of object

As per the documentation,

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

Note that your attempt included () in the method name string, which would be wrong


Let me extend @mark-baker's answer:

if you want to call a static method of another class, you have to put the full namespace into the quotes:

return array_map('Other\namespace\CustomClass::pay', $model_list);

Using the class per use is not enough:

// this is not enough:
// use Other\namespace\CustomClass;
return array_map('CustomClass::pay', $model_list); //does not work

Tags:

Php

Array Map