1

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!

5
  • 1
    How certain are you that this is running PHP 7? You've confirmed this with phpinfo()? What's the parse error message for the Database::fetch_assoc code? Commented Nov 20, 2017 at 1:44
  • I have, it's running PHP 7.1.11 x64. That's also the first thing I checked since I thought that it was a php 5.3 thing. Parse error for the Database::fetch_assoc code is exactly the same. Commented Nov 20, 2017 at 1:47
  • 2
    I'm curious about how you checked, though. It's possible for there to be multiple versions of PHP on a server. If you replace the password_hash() line with phpinfo() the output shows PHP 7? What do the couple of lines before/after the problematic line say? Commented Nov 20, 2017 at 1:48
  • try it running on php 5.6 Commented Nov 20, 2017 at 1:53
  • Well that being a good point. I checked it in the root of the website (test.php) that shows up as 7.1.11. But when I try it in the script that actually loads the functions.php file. It happily tells me I'm running PHP 5.3 :/ . So much thanks for that suggestion. Now for the new odd thing, why does my PHP version switch to 5.3 when I go into deeper directories (test.php is in the root) functions.php is 1 folder deeper.. Commented Nov 20, 2017 at 2:01

1 Answer 1

4

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!

Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad I could help. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.