php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68895 Error on parse_str() example
Submitted: 2015-01-23 19:16 UTC Modified: 2015-01-23 21:06 UTC
From: nazarenolorenzo at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
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:
MUST BE VALID
Solve the problem:
4 + 49 = ?
Subscribe to this entry?

 
 [2015-01-23 19:16 UTC] nazarenolorenzo at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.parse-str
---
The first part of the current example prints $arr, which is never declared:

<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz

Expected result:
----------------
Instead, it should be:
<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
$arr = parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-23 19:20 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2015-01-23 19:20 UTC] aharvey@php.net
It's (unfortunately) correct: if the second argument isn't given to parse_str(), it creates variables in the current scope.
 [2015-01-23 21:06 UTC] nazarenolorenzo at gmail dot com
You're right. I was confused about how it works. 
Thanks for the clarification
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 06:01:29 2024 UTC