L
L
leha782015-11-10 18:13:32
PHP
leha78, 2015-11-10 18:13:32

Why is there an error in the code (code inside)?

public function oauth($path, array $parameters = [])
    {
        $response = [];
        $this->resetLastResponse();
        $this->response->setApiPath($path);
        $url = sprintf('%s/%s', self::API_HOST, $path);
        $result = $this->oAuthRequest($url, 'POST', $parameters);

        if ($this->getLastHttpCode() != 200) {
            throw new TwitterOAuthException($result);
        }

        parse_str($result, $response);
        $this->response->setBody($response);

        return $response;

Parse error: syntax error, unexpected '[' in /home/../twitteroauth-master/src/TwitterOAuth.php on line 155
155 line is public function oauth($path, array $parameters = [])
and the error is $ response = [];

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Yarkov, 2015-11-10
@leha78

public function oauth($path, $parameters = array())

M
Melkij, 2015-11-10
@melkij

Check your PHP version. You are using some kind of too museum, you need at least museum 5.4, it is better to use the current 5.6

I
Ivanq, 2015-11-10
@Ivanq

In this version, apparently, the definition of an array through brackets is not supported.

A
Andrey Dyrkov, 2015-11-10
@VIKINGVyksa

why are you assigning a value to the parameter?

public function oauth($path, array $parameters = [])
//наверно надо так 
public function oauth($path, array $parameters)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question