4
I have the following folder and file structure:
-api
-v1
-libs
-Slim
-Facebook
-autoload.php
-index.php
-login.php
Inside the "index.php" I do the include of "login.php":
require_once 'login.php';
Inside "login.php" I do the include of the file "libs/Facebook/autoload.php" and then try to use a class:
require_once 'libs/Facebook/autoload.php';
use Facebook\FacebookSession;
The following error is returned:
Parse error: syntax error, Unexpected 'use' (T_USE)
"autoload.php" contains the following code:
spl_autoload_register(function ($class){
$prefix = 'Facebook\\';
$base_dir = __DIR__;
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
What I’m doing wrong so the autoload doesn’t work properly?
The
use Facebook\FacebookSession;
is being called within a method or function?– Guilherme Nascimento
What version of php you are using?
– rray