The following is a static method of a given class:
class myClass {
public static function contentFilter($content) {
// ... irrelevant code
if (!function_exists('replaceCallback')) {
function replaceCallback($matches) {
// relevant line of code
$result = return_setting($params);
return $result;
};
}
$new_content = preg_replace_callback($regex, 'replaceCallback', $new_content);
return $new_content;
}
}
The function return_setting inside replaceCallback is a globalized version of the static returnSetting method from the same class. The code works, but it doesn't feel right that I have to globalize the function before I can access it, I feel like I should be able to do self::returnSetting(). When I do this, I get the error ofc.
Fatal error: Cannot access self:: when no class scope is active
Doing myClass::returnSetting works, but it's kind of awkward to refer to the class by its name inside one of its methods. Or can one do self::replaceCallback in the replace_callback function? Is there any preferred way to do this?
PS: I need to pass the replaceCallback function as a string to preg_replace_callback because I need to support PHP 5.2.