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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nazarenolorenzo at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 11:01:29 2024 UTC