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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC