-2

I lost my evening on this and I feel like I need somebody other to check this, I'm probably completely blind.

define('FACEBOOK_SDK_V4_SRC_DIR', '/var/www/rateanything/facebook-sdk/src/Facebook');
require('/var/www/rateanything/facebook-sdk/autoload.php');
use Facebook;
FacebookSession::setDefaultApplication('my_app_id', 'my_app_secret');
$session = new FacebookSession($fbtoken);
$request = new FacebookRequest($session,'GET','/me?fields=email,name,gender');

Why this is not duplicate: Because that question has not this error. I'm getting this parse error.

I'm using PHP 5.4.

tensojka
  • 302
  • 1
  • 5
  • 20

2 Answers2

13

Is that code wrapped inside a function? The use keyword can only be applied on the outermost scope of your file.

Basically, move use Facebook; to the top of the file.

Alternatively, you could probably reference the namespace in which FacebookSession and FacebookRequest is defined. Like so:

define('FACEBOOK_SDK_V4_SRC_DIR', '/var/www/rateanything/facebook-sdk/src/Facebook');
require('/var/www/rateanything/facebook-sdk/autoload.php');
Facebook\FacebookSession::setDefaultApplication('my_app_id', 'my_app_secret');
$session = new Facebook\FacebookSession($fbtoken);
$request = new Facebook\FacebookRequest($session,'GET','/me?fields=email,name,gender');
  • It's not in a function, but it's in "if", where I check if the person is logging in via G+ or Facebook. – tensojka Apr 15 '15 at 15:59
0

So based on the error this is the problem line

use Facebook;

Without knowing what's in that include it's hard to say, but it doesn't look like you're aliasing anything. In fact, if you're autoloading (which seems like a safe bet) you shouldn't use an alias like that.

Normally you'd use it like this

include 'facebook.php';
use Facebook;
\Facebook\SomeClass::staticFunction($var);
$class = new \Facebook\OtherClass();

Check out the manual for more details and examples on how to use use

Machavity
  • 30,841
  • 27
  • 92
  • 100