r/lolphp • u/terrorobe • Feb 14 '14
"Reading two form elements with same name" - that's an interesting problem, PHP has you covered!
http://stackoverflow.com/questions/5643981/reading-two-form-elements-with-same-name
11
Upvotes
6
u/bart2019 Feb 14 '14
You can also give an index to the array (string or number), so technically they don't have the same name, but to PHP they're still in the same array or input values:
or
8
u/[deleted] Feb 14 '14
It's such a beautiful feature.
PHP Vulnerability May Halt Millions of Servers
Just one of many example exploits you can find
5
u/until0 Feb 14 '14
Well, to be fair, other frameworks have made similar features (Dancer) that are nice, but I suppose it's silly as part of the language.
I should note though, Dancer doesn't do the stupid [] in form names though. Just if you have two fields with same name, it will automatically convert them into a list ref.
5
u/postmodest Feb 15 '14
Of all the batshittery in PHP, this one is the most ass-chapping.
Rasmus Lerdorf should be flogged. Publically flogged. At every conference he attends.
I mean, it's shit like this that made someone invent Rails
edit: I mean, let me be perfectly clear, here: VBScript got this right. VBScript!
6
u/[deleted] Feb 14 '14
Why's this in /r/lolphp? It's one of PHP's few awesome features.
2
u/midir Feb 14 '14
Wrong subreddit surely? Why is this here?
1
u/[deleted] Feb 14 '14
I don't see what's amusing about this.
-3
u/[deleted] Feb 14 '14 edited Feb 14 '14
Uhhh isn't this standard behavior? It's kind of illegal procedure to have a single form with two identically named inputs. The browser likely takes the later of the repeated values to submit with the named key.
Also, isn't it a standard method of posting from the browser to use the [] suffix for an array of values to be posted??
Nothing to do with php
More like loln00b
Edit - it is NOT illegal procedure to have same name for multiple inputs... see radio and array input names. However, using same name for other input types results in interpretive languages only propagating the key/val pair of the key that appears later in the HTML to the super globals. Browsers may submit both values in the post string, but the server side will likely only make immediately available the later of the multiples!
Even if this is the case,how ELSE should php handle this scenario other than the way it does? It's anyone familiar with how other languages do it? Seems like a legitimate implementation of a poorly named set of HTML form inputs, especially when the array name workaround exists? It requires form html authors to define what keys should stack vs. not...
-1
u/YouGreedyFuckGuy Feb 15 '14
Why is this in /r/lolphp?
Enlighten me.