array_merge()[function.array-merge]:参数#1不是数组

I am trying to use Google-API-PHP-Client and its base class is throwing following error:

Severity: Warning

Message: array_merge() [function.array-merge]: Argument #1 is not an array

Filename: libraries/Google_Client.php

Line Number: 107

Code around like 107 is something like:

public function __construct($config = array()) {
    global $apiConfig;
    $apiConfig = array_merge($apiConfig, $config);
    self::$cache = new $apiConfig['cacheClass']();
    self::$auth = new $apiConfig['authClass']();
    self::$io = new $apiConfig['ioClass']();
  }

I understand that global $apiConfig is not initialized as array that's why array_merge is throwing error. But when I change it to global $apiConfig = array();, got another error Parse error: syntax error, unexpected '=', expecting ',' or ';' in C:\Softwares\xampp\htdocs\testsaav\application\libraries\Google_Client.php on line 106

I am using Codeigniter 2.3 with XAMPP which has PHP 5.3

Initialize your array in your function (if necessary)

public function __construct($config = array()) {
    global $apiConfig;
    $apiConfig = (isset($apiConfig) && is_array($apiConfig)) ? $apiConfig : array(); // initialize if necessary
    $apiConfig = array_merge($apiConfig, $config);
    self::$cache = new $apiConfig['cacheClass']();
    self::$auth = new $apiConfig['authClass']();
    self::$io = new $apiConfig['ioClass']();
  }

Check your server logs and see if there is an error related to the require_once('config.php') in Google_Client.php (If the file wasn't found, the script should have stopped).

When you do your require_once('Google_Client.php'), the following code is executed from that file. After you do your require, $apiConfig should be visible to your script.

// hack around with the include paths a bit so the library 'just works'
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());

require_once "config.php";
// If a local configuration file is found, merge it's values with the default configuration
if (file_exists(dirname(__FILE__)  . '/local_config.php')) {
  $defaultConfig = $apiConfig;
  require_once (dirname(__FILE__)  . '/local_config.php');
  $apiConfig = array_merge($defaultConfig, $apiConfig);
}

Note that you do not touch config.php. If you need to override anything in there, you create local_config.php.

From my system with PHP 5.3 I used this script. The script as show below throws no errors. Unsetting the $apiConfig replicates your error.

<?php

require_once('src/Google_Client.php');

print_r($apiConfig);
// uncommenting the next line replicates issue.
//unset($apiConfig);
$api = new Google_Client();

?>