任何人都可以帮助我进行以下代码错误检测吗?它显示错误
$headerList = [];
和(new DumpHTTPRequestToFile)->execute('./dumprequest.txt');
请帮我收到xml请求。
<?php
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data="";
foreach ($this->getHeaderList() as $name => $value) {
//$data .= $value . "\n";
}
$data .= "";
file_put_contents(
$targetFile,
$data . file_get_contents('php://input') . "\n"
);
echo("Done");
}
private function getHeaderList() {
$headerList = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/',$name)) {
// convert HTTP_HEADER_NAME to Header-Name
$name = strtr(substr($name,5),'_',' ');
$name = ucwords(strtolower($name));
$name = strtr($name,' ','-');
// add to list
$headerList[$name] = $value;
}
}
return $headerList;
}
}
(new DumpHTTPRequestToFile)->execute('./dumprequest.txt');
?>
答案 0 :(得分:0)
这看起来像是使用过时版本的PHP,作为Dreamweaver的处理程序或在您的服务器上。这些是PHP5.3中的语法错误,但在PHP5.4中允许,称为短数组语法和实例化简写:http://php.net/manual/en/migration54.new-features.php
您可以使用$headerList = array()
向后兼容PHP5.3及以下版本。
类似于PHP5.4之前版本中的can’t use the instantiation shorthand;你需要:
$dump = new DumpHTTPRequestToFile();
$dump->execute(...);
鉴于PHP5.3已过时,我强烈建议您更新PHP版本,而不是通过代码搜索以使其可互操作。