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
 [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: Thu Apr 25 01:01:30 2024 UTC