getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

add parse_str() to str::parse() #222

Closed sebsel closed 7 years ago

sebsel commented 7 years ago

I was expecting parse_str() to be a mode of str::parse(), but it was not. I think it’s a good addition, especially because parse_str() by default throws stuff in the global scope, so you need to pass in a variable by reference and all that stuff.

Also added tests!

From php.net:

$str = "first=value&arr[]=foo+bar&arr[]=baz";

// Recommended
parse_str($str, $output);
echo $output['first'];  // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

// DISCOURAGED
parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz

And now:

$a = str::parse($str, 'form');
sebsel commented 7 years ago

You are right! I renamed to query.

Re whitespace: I did put it in a separate commit, to keep things clear, but yeah, the 'changes' overview gets cluttered. I will (and just did) discard / ignore whitespace changes from now on.