由于PHP 5.2中的匿名函数问题而在服务器上出错

I'm using "google-api-php-client" library which is working fine on local system but it's giving following error on server as it's version is 5.2!

syntax error, unexpected T_FUNCTION, expecting ')'

So I have two questions here, if we can fix this error by doing some changes in code to make it work with this function? Below is the code of autoload.php

spl_autoload_register(
function ($className) {
  $classPath = explode('_', $className);
  if ($classPath[0] != 'Google') {
    return;
  }
  // Drop 'Google', and maximum class file path depth in this project is 3.
  $classPath = array_slice($classPath, 1, 2);

  $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
  if (file_exists($filePath)) {
    require_once($filePath);
  }
}
);

but I'm not sure how to change the above to solve this issue and also is there any library which can run on php version 5.2? As if I use this, it might be possible that it start giving error on some other functionality. Thanks!

It seems your php version not knows about anonymous functions or closures. Try to use named one:

function autoloadGoogleApi($className) {
  $classPath = explode('_', $className);
  if ($classPath[0] != 'Google') {
    return;
  }
  // Drop 'Google', and maximum class file path depth in this project is 3.
  $classPath = array_slice($classPath, 1, 2);

  $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
  if (file_exists($filePath)) {
    require_once($filePath);
  }
}

spl_autoload_register('autoloadGoogleApi');

Still, I'm also want to point out, that php version you specifying is very old, so I'm suggesting to really consider option of upgrading.

UPD: 3v4l test