SimpleSamlPHP unexpected T_FUNCTION in GenerateGroups.php

240 views Asked by At

I received this error when trying to test simplesamlphp Parse error: syntax error, unexpected T_FUNCTION in /simplesamlphp/modules/core/lib/Auth/Process/GenerateGroups.php on line 139

What is causing this?

I'm running PHP 5.2

1

There are 1 answers

0
Brian F Leighty On

This is because this is using an anonymous function. I replaced this method with the one below as well as an extra one and it now works correctly in 5.2. SimplesamlPHP's requirements state it only needs PHP 5.1 or 5.2 but this obviously is incorrect without this code change.

/**
 * Escape special characters in a string.
 *
 * This function is similar to urlencode, but encodes many more characters.
 * This function takes any characters not in [a-zA-Z0-9_@=.] and encodes them with as
 * %<hex version>. For example, it will encode '+' as '%2b' and '%' as '%25'.
 *
 * @param string $string  The string which should be escaped.
 * @return string  The escaped string.
 */
private static function escapeIllegalChars($string) {
    assert('is_string($string)');

    return preg_replace_callback('/([^a-zA-Z0-9_@=.])/',
        array(self,escapeIllegalCharsPregCallback),
        $string);
}

private static function escapeIllegalCharsPregCallback($m) {
    return sprintf("%%%02x", ord($m[1]));
}