PHP - strange behavior after calling functions on a map

I am having a rather strange browser reaction when calling this PHP script.

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

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

      

I already noticed there is a bug in there. The call syntax is incorrect as it should be like this:

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

      

The point is that the browser's reaction to this error is not what it should be.

Running this script results in the message "The connection has been reset". The server is up and running correctly as the other PHP files (and this one after fixing the error) are working fine.

But what really puzzles me is what the browser navigation bar does. When I click on the url

localhost/cerdo.php?v=a

      

the content of the panel changes to

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

      

The www.localhost.com part seems to only happen in Firefox. I tried it on Chromium and even though it showed a similar message ("No data"), the URL remains the same.

What's happening? Does this make sense? Shouldn't PHP be reporting a syntax error? And why will Firefox server redirect to www.localhost.com?

+3


source to share


3 answers


Should PHP not report a syntax error?

Not. If PHP does not report $map($_GET['v']);

because the syntax error is because it is expecting syntactically correct code. This way it ends up doing some very strange things that you wouldn't expect. This results in your browser being redirected to some inexplicable location.



The key here is understanding what it means $map($_GET['v']);

.

+1


source


The redirection has nothing to do with your code. How your environment is configured eg. are you using Xampp etc? In this case, make sure you have an index.php or .htaccess file in your web root, or whatever contains a redirect script.



0


source


If this is not your first time with you, you will ignore this:

I think your problem is that the OS couldn't recognize the domain name (and the OS is extending it). On 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

(You may need to restart your computer.) It should solve your

0


source







All Articles