我在尝试测试simplesamlphp时收到此错误 解析错误:语法错误,第139行/simplesamlphp/modules/core/lib/Auth/Process/GenerateGroups.php中的意外T_FUNCTION
造成这种情况的原因是什么?
我正在运行PHP 5.2
答案 0 :(得分:2)
这是因为这是使用匿名函数。我用下面的方法替换了这个方法以及额外的方法,现在它在5.2中正常工作。 SimplesamlPHP的要求声明它只需要PHP 5.1或5.2,但如果没有代码更改,这显然是不正确的。
/**
* 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]));
}