0

i am trying to install a sdk on a public cloud service.The code is shown as follow:

<?php 
 echo ( '<meta charset="utf-8">');
date_default_timezone_set('PRC');
require_once __DIR__ . '/lib/KdtApiClient.php';

$appId = 'xxx';
$appSecret = 'xxx';
$client = new KdtApiClient($appId, $appSecret);


$method = 'kdt.users.weixin.followers.get';
$params = [
       // 'tid' => 'E20150126200526848473',
    //'num_iid' => 1005950256201501260011172648,
    //'title' => 'api 测试商品 编辑 __ 22',
    //'desc' => 'description here',
    //'post_fee' => 0.2,
    'page_size'=>5000,
];

$files = [
    [
        'url' => __DIR__ . '/file1.png',
        'field' => 'images[]',
    ],
    [
        'url' => __DIR__ . '/file2.jpg',
        'field' => 'images[]',
    ],
];


echo '<pre>';
var_dump( 
    $client->post($method, $params, $files)
);
echo '</pre>';

?>

I got this error:

Parse error: syntax error, unexpected '[' in php-sdk/index.php on line 12

The code works well on local xampp.Is there anyone can tell me what's the problem?

1
  • 5
    The public server is running a version of PHP below 5.4 where the only syntax for declaring an array is $arr = array(...); Commented Feb 3, 2015 at 3:31

1 Answer 1

1

The issue you are encountering is most likely due to different PHP versions.

On line 12 you are using the short array syntax to create an array on the files variable. $files = [... This syntax was introduced in PHP 5.4 (See second point). However I think the cloud service is not using 5.4, which is why you don't have the short array syntax. The easy solution would be to use $files = array( instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.