I'm looking for a way to replace __NAMESPACE__
in the following code:
namespace classes\utility;
class Cleanse
{
public static function escape($values)
{
return is_array($values) ?
array_map(__NAMESPACE__.'\Cleanse::escape', $values) :
htmlentities($values, ENT_QUOTES, 'UTF-8');
}
}
From doing some reading, I tried this:
public static function escape($values)
{
return is_array($values) ?
array_map([static::class, 'escape'], $values) :
htmlentities($values, ENT_QUOTES, 'UTF-8');
}
but got this error:
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
and it referred to the array_map
line of code.
I'm looking for a solution that's compatible with PHP version 5.4.4 and above, and something that is not going to be deprecated any time soon.
EDIT: I was unable to find the answer in the proposed duplicate post because it is so long. Therefore, I do not agree that this is a duplicate posting.