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

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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable