PHP - 在地图中调用函数后的奇怪行为

I'm experiencing quite a strange reaction from the browser when invoking this PHP script.

<?php
    $map = array(
        'a' => function(){
                print_r('a');
            },

        'b' => function(){
                print_r('b');
            }
    );  
    $map($_GET['v']);
?>

I already noticed that there is a mistake there. The syntax of the call is wrong, as it should be like this:

$map[$_GET['v']]();

The thing is that the reaction of the browser to this mistake is not what it should be.

The result of running this script is a 'The connection was reset' message. The server is up and running correctly, as other PHP files (and this one after correcting the mistake) run perfectly.

But what is actually puzzling me is what the navigation bar of the browser does. When I punch in the URL

localhost/cerdo.php?v=a

the content of the bar changes to

www.localhost.com/cerdo.php?v=a

The www.localhost.com part seems to happen only in Firefox. I've tried it on Chromium and, despite showing a similar message ('No data received') the URL stays the same.

What is happening? Does this make any sense? Shouldn't PHP be reporting a syntax error? And why on earth would Firefox redirect to www.localhost.com?

The redirection doesn't have anything to do with your code. How is your environment setup, e.g. are you using Xampp etc.? In that case make sure there is any index.php or .htaccess or anything else that contains a redirection script in your web root.

If it's not your first time with you dev enviroment, please ignore this:

I think your problem is: the OS couldn't recognise the domain name (and the OS extends it). Under Windows you can find the 'hosts' file here:

"%SYSTEMROOT%\System32\drivers\etc\"

Add this line to the end of the file:

127.0.0.1 localhost

(Maybe you should restart your computer.) It should solve your

Shouldn't PHP be reporting a syntax error?

No. If PHP is not reporting $map($_GET['v']); as syntax error is because it is expecting the code to be syntactically valid. So it ends up executing some very weird stuff that you are not expecting. This results in redirecting your browser to some unexplainable location.

The key here is to understand what $map($_GET['v']); actually means.