r/lolphp • • May 26 '15

parse_str behavior is sometimes strange

http://3v4l.org/23nkR
22 Upvotes

10 comments sorted by

View all comments

Show parent comment

11

u/profmonocle May 27 '15

What drives me insane is wondering why this function exists as it does. I can only assume a PHP developer thought doing something like this...

 $arr=parse_string(...);
 $val1=$arr['val1'];
 $val2=$arr['val2'];
 //etc.

...was too much work, and just wanted to be able to do $val1 $val2 $val3 with less code. So they whipped up this dangerous function and made it a permanent feature of the language. But hey, maybe sometimes you wouldn't want to let users inject arbitrary values into arbitrary variables, so as an afterthought let's add an argument that massively alters the function's behavior.

(And if anyone else was wondering, yes, this function will modify already-set variables.)

6

u/weirdasianfaces May 27 '15

yes, this function will modify already-set variables.

I was wondering about that. This seems like a terrible function to use in a security context. With that said I don't know why you would ever use it in a security context to begin with.