
Today I decided to figure out how PHP defines the key in the $ _GET array for parameters received by the GET method, respectively. To be honest, I did not expect to see such illogicality in the work of this mechanism. Although in general, why it happened, it is clear ...
So, immediately to the practice. How do you think the $ _GET line will display a line like this: "? Aa [bb] [cc = 11"? In principle, the options are not so few, among them are logical, and not very. As a result, in PHP we get the following array keys: $ _GET ['aa'] ['bb'] = 11. Where did the "cc" go? What will give "? Aa [bb] cc = 11"? Same thing ($ _GET ['aa'] ['bb'] = 11). Where “cc” has gone again is not clear. But the most interesting thing to come!
What will give "? Aa [bbb = 11"? Of course $ _GET ['aa_bbb'] = 11, how could you not guess, the same intuitive continuation of the examples above :)
"? aa [bb [ccc]] = 11" gives $ _GET ['aa'] ['bb [ccc'] = 11. The second bracket was stolen again!
')
Well, the peak of the program: "? [Aa] = 7". var_dump ($ _ GET) will return: Array () is an empty array. “Aaaah, where is my gett? ..” It would probably be more logical to at least create the key $ _GET [']]. However, in all these controversial cases there are a lot of options and one can argue about their correctness for a long time.
These are the metamorphosis. This behavior is partly explained by the fact that in the first versions of the language, the parameters were not parsed into the array, but into variables. Then the forbidden characters were taken to be replaced by underscores. In one of the examples above, there is such a replacement. It is valid when this parameter is not considered an array. But if the parameter is recognized as an array, a new cunning logic is turned on, which in some cases simply throws away too much, in others it throws back only part of the disagreeable, and part of it completely shoves the key. Not intuitive, not logical.
UPD . It is probably worth adding that the goal of this post is by no means once again to curse PHP. I understand perfectly well that otherwise I could hardly get out in the conditions in which this interesting language developed :) But, as they say, forewarned is forearmed :)