dongzhi6927
2017-11-20 01:26
浏览 64
已采纳

PHP奇怪的解析错误

So I'm pulling my hair out at this point :/

I've got an IIS webserver set up with PHP 7.1.11 on Windows Server 2012 R2 Datacenter Edition , when I load up a page it throws a parse error:

Parse error: syntax error, unexpected '[' in functions.php on line 138

Now the actual piece of code where this goes wrong is the following

$hash = password_hash($nieuwWachtwoord,PASSWORD_DEFAULT, ["cost" => 13]);

And when I changed it to

$hash = password_hash($nieuwWachtwoord,PASSWORD_DEFAULT,array("cost" => 13));

It executes the code without any problem.

But then when I called another function running the following code

 Database::fetch_assoc("SQL-STRING", array($id))[0]['cdate'];

It also throws a parse error. The frustrating thing is that this shouldn't happen since declaring an array like that on the go should be possible in php7.1 (and this same code on a Linux machine running ubuntu with apache2 works like it should)

Also the last case where I "assume" an array is returned should at most throw an undefined index error instead of a parse error.

Does anyone know what the cause may be?

Thanks in advance!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanlongnao0028 2017-11-20 02:06
    已采纳

    Okay thanks to ceejayoz I found out the problem. When I put phpinfo() in a file called test.php it told me I was running PHP 7.1 .

    Now the file actually calling the script that was throwing parse errors had a .html extension. And IIS had a different Handler mapping for html files pointing to the old 5.3 executable.

    Now that I changed the handler for .html files it all works like a charm again!

    Many thanks!

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题