1

Can any one help me in the following code error detection? It displays error on $headerList = []; and (new DumpHTTPRequestToFile)->execute('./dumprequest.txt'); Please help me in receiving xml request.

    <?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');
?>

enter image description here

Ajnabi
  • 23
  • 4

1 Answers1

0

This looks like you are using an outdated version of PHP, either as Dreamweaver’s handler or on your server. These are syntax errors in PHP5.3 but permitted in PHP5.4, called short array syntax and instantiation shorthand: http://php.net/manual/en/migration54.new-features.php

You can use $headerList = array() for backwards compatibility with PHP5.3 and below.

Similarly you can’t use the instantiation shorthand in versions before PHP5.4; you’ll need:

$dump = new DumpHTTPRequestToFile();
$dump->execute(...);

Given that PHP5.3 is way out of date, I would strongly suggest updating your PHP versions rather than trawling through code to make it interoperable.

cmbuckley
  • 40,217
  • 9
  • 77
  • 91