PHP 中的关键字 "use" 给出了一个"Parse error: syntax error, unexpected T_STRING"



我想使用这个php代理脚本。我下载了压缩包,提取了内容并上传到服务器。我创建了一个新的index.php文件,并将库示例中的代码复制到其中。

(注意:我是在PHP版本5.2.17-nmm2)

lib需要Symphony,所以我把它也上传到同一个目录中。当我运行脚本时,我得到:

解析错误:语法错误,unexpected T_STRING, expected

第3行index.php中的T_CONSTANT_ENCAPSED_STRING或'('
<?php
use ProxyFactory;
use ProxyResponseFilterRemoveEncodingFilter;
use SymfonyComponentHttpFoundationRequest;
require 'vendor/autoload.php';
// Create the proxy factory.
$proxy = Factory::create();
// Add a response filter that removes the encoding headers.
$proxy->addResponseFilter(new RemoveEncodingFilter());
// Create a Symfony request based on the current browser request.
$request = Request::createFromGlobals();
// Forward the request and get the response.
$response = $proxy->forward($request)->to('http://example.com');
// Output response to the browser.
$response->send();
?>

PHP 5.2不支持名称空间。您至少需要升级到PHP 5.3,尽管建议升级到PHP 5.6,因为其他版本都过时了。如果你使用的是共享主机,你应该考虑找一个新的主机。(您的php版本很长时间没有收到安全补丁,应该被认为容易受到攻击)。

相关内容

最新更新