找到你要的答案

Q:new facebook T_OBJECT_OPERATOR error

Q:新的脸谱网t_object_operator误差

i get this error:

syntax error, unexpected T_OBJECT_OPERATOR

in...

$this->loadState();
if ($this->isValidRedirect()) {
  $params = array(
    'client_id' => FacebookSession::_getTargetAppId($this->appId),
    'redirect_uri' => $this->redirectUrl,
    'client_secret' =>
      FacebookSession::_getTargetAppSecret($this->appSecret),
    'code' => $this->getCode()
  );
  $response = (new FacebookRequest(
    FacebookSession::newAppSession($this->appId, $this->appSecret),
    'GET',
    '/oauth/access_token',
    $params
  ))->execute()->getResponse();
  if (isset($response['access_token'])) {
    return new FacebookSession($response['access_token']);
  }
}
return null;

this is the line of error: ))->execute()->getResponse();

我得到这个错误:

语法错误,不t_object_operator

在…

$this->loadState();
if ($this->isValidRedirect()) {
  $params = array(
    'client_id' => FacebookSession::_getTargetAppId($this->appId),
    'redirect_uri' => $this->redirectUrl,
    'client_secret' =>
      FacebookSession::_getTargetAppSecret($this->appSecret),
    'code' => $this->getCode()
  );
  $response = (new FacebookRequest(
    FacebookSession::newAppSession($this->appId, $this->appSecret),
    'GET',
    '/oauth/access_token',
    $params
  ))->execute()->getResponse();
  if (isset($response['access_token'])) {
    return new FacebookSession($response['access_token']);
  }
}
return null;

这是错误的:-))execute() - >;>;getresponse();

answer1: 回答1:

As I though, your PHP version is 5.3 (< 5.4). In your code you're trying to access class members on instantiation, an option that was introduced only on PHP 5.4.

Class member access on instantiation has been added, e.g. (new Foo)->bar().

Source: http://php.net/manual/en/migration54.new-features.php

Therefore, you have to change your code and separate that part into 2 steps, as the following:

$fbRequest = new FacebookRequest(
    FacebookSession::newAppSession($this->appId, $this->appSecret),
    'GET',
    '/oauth/access_token',
    $params
  );

$response = $fbRequest->execute()->getResponse();

As I though, your PHP version is 5.3 (< 5.4). In your code you're trying to access class members on instantiation, an option that was introduced only on PHP 5.4.

Class member access on instantiation has been added, e.g. (new Foo)->bar().

来源:http://php.net/manual/en/migration54.new-features.php

因此,您必须更改代码并将该部分分为2个步骤,如下所示:

$fbRequest = new FacebookRequest(
    FacebookSession::newAppSession($this->appId, $this->appSecret),
    'GET',
    '/oauth/access_token',
    $params
  );

$response = $fbRequest->execute()->getResponse();
php  facebook