Edit report at https://bugs.php.net/bug.php?id=64607&edit=1

 ID:                 64607
 Updated by:         larue...@php.net
 Reported by:        sdeonline at gmail dot com
 Summary:            If second parameter is present, parse_str should
                     return the generated array.
 Status:             Open
 Type:               Feature/Change Request
 Package:            Strings related
 Operating System:   Irrelevant
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

it will be big BC break,  and I don't see any strong reason why need this.

thanks


Previous Comments:
------------------------------------------------------------------------
[2013-04-07 22:22:47] sdeonline at gmail dot com

Description:
------------
---
>From manual page: 
>http://www.php.net/function.parse-str#refsect1-function.parse-
str-returnvalues
---

In my humble opinion parse_str should be able to return the array it generates 
when it's not parsing to global vars. 
This could save lines of code and be more understandable.

This is quite useful if converting a received method variable as a parameter to 
another method that requires an array parameter. Because you don't need an 
extra 
line to just parse the string.

Test script:
---------------
// Initial string
$string = 'foo=bar&fruit=apple';

// This works:
// parse_str($string,$array);
// print_r($array);

// Now this would be better!
print_r(parse_str($string,true));

// Or the easy to the eyes version (but it quite misses the point.
$array = parse_str($string,true);
print_r($array);

Expected result:
----------------
Array 
( 
    [foo] => bar 
    [fruit] => apple 
)
Array 
( 
    [foo] => bar 
    [fruit] => apple 
)

Actual result:
--------------
Fatal error: Only variables can be passed by reference on line 9


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64607&edit=1

Reply via email to