|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64607 If second parameter is present, parse_str should return the generated array.
Submitted: 2013-04-07 22:22 UTC Modified: 2013-04-11 12:22 UTC
From: sdeonline at gmail dot com Assigned: ab (profile)
Status: Closed Package: Strings related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
43 - 21 = ?
Subscribe to this entry?

 [2013-04-07 22:22 UTC] sdeonline at gmail dot com
From manual page:

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!

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

Expected result:
    [foo] => bar 
    [fruit] => apple 
    [foo] => bar 
    [fruit] => apple 

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-08 02:43 UTC]
it will be big BC break,  and I don't see any strong reason why need this.

 [2013-04-11 12:22 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2013-04-11 12:22 UTC]
Agree, that shouldn't be implemented due to too much change for no obvious reason. There are countless questions then, like modify your snippet:

$array = true;
parse_str($string, $array);

What should happen then? Is $array an array() now or true?

@sdeonline if you feel like that's important, you could come up with an RFC clearing up doubtful places.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 14:01:24 2023 UTC