Twilio PHP的“使用”返回一个错误意外T_STRING

问题描述:

我试图创建一个Twilio令牌生成和我的项目返回此错误:Twilio PHP的“使用”返回一个错误意外T_STRING

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in file dir on line 8

8号线中有use Twilio\Rest\Client;。我安装了PHP Twilio SDK,这是我唯一的错误。

问题是:此SDK中的几乎所有文件都有use ...措辞。我为此做了什么来正常工作?

我的文件VTC.php做到这一点:

<?php 

// Required if your environment does not handle autoloading 
require __DIR__ . '/vendor/autoload.php'; 

// Use the REST API Client to make requests to the Twilio REST API 
use Twilio\Rest\Client; 

$id = $_GET['id']; 


// Substitute your Twilio AccountSid and ApiKey details 
$accountSid = 'xxx'; 
$apiKeySid = 'xxx'; 
$apiKeySecret = 'xxx'; 

// Create an Access Token 
$token = new Services_Twilio_AccessToken(
    $accountSid, 
    $apiKeySid, 
    $apiKeySecret, 
    $ttl=3600, 
    $identity='user'.$id 
); 

// Grant access to Conversations 
$grant = new Services_Twilio_Auth_ConversationsGrant(); 
$grant->setConfigurationProfileSid('configurationProfileSid'); 
$token->addGrant($grant); 

// Serialize the token as a JWT 
echo $token->toJWT(); 
?> 
+0

我的服务器有php 5.2 –

+1

PHP Namespacing是在PHP 5.3中引入的; PHP 5.2已经超过6年正式报废了,也许你应该考虑升级 –

PHP 5.2太低运行您正在使用的库。假设您使用的是this library,composer.jsonhere)表示最低版本为5.3。

我会提醒你,虽然5.6目前是PHP的oldest supported version

+0

我想这个..是我的虚拟主机的默认版本。我试着更新5.6并重试。 THKS! –

+0

如果他们提供5.2作为默认,我不会使用您的虚拟主机。如果他们如此落后,谁知道他们如何处理你的信用卡数据和密码......我会建议找到一个更有信誉的虚拟主机。 – Scopey

+0

我现在更新我的php 5.6。在我的phpadmin我看到这个: PHP版本:5.6.29-0 + deb8u1和错误继续... 更好奇的是,如果我使用phpinfo()函数它告诉我,PHP是5.2 –