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!

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

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样