note 112568 added to function.parse-str

From: Date: Sun, 30 Jun 2013 16:43:09 +0000
Subject: note 112568 added to function.parse-str
Groups: php.notes 
Request: Send a blank email to php-notes+get-195409@lists.php.net to get a copy of this message
Beware using parse_str in a function that has vars passed by reference. It seems that parse_str actually creates new vars even if vars of the same name exist. If you pass by ref vars of the same name as those in a query string being parsed new LOCAL vers will be created and you won't get any values passed back to the caller (relates to what Maikel mentioned below) An unrealistic example (vaguely related to what I was doing when I found this out)... function get_title($query,&$title) { parse_str($query); $title=str_replace("_"," ",$title); } $title="foo"; $query = "context=something&title=Title_of_Something"; get_title($query,$title); echo $title .... "foo" ---- Server IP: 69.147.83.199 Probable Submitter: 84.92.57.136 ---- Manual Page -- http://php.net/manual/en/function.parse-str.php Edit -- https://master.php.net/note/edit/112568 Del: integrated -- https://master.php.net/note/delete/112568/integrated Del: useless -- https://master.php.net/note/delete/112568/useless Del: bad code -- https://master.php.net/note/delete/112568/bad+code Del: spam -- https://master.php.net/note/delete/112568/spam Del: non-english -- https://master.php.net/note/delete/112568/non-english Del: in docs -- https://master.php.net/note/delete/112568/in+docs Del: other reasons-- https://master.php.net/note/delete/112568 Reject -- https://master.php.net/note/reject/112568 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195409) next »