Bug #64325 [Opn->Fbk]: Issue in automatic $_POST array handling
Edit report at https://bugs.php.net/bug.php?id=64325&edit=1
ID: 64325
Updated by: laruence@php.net
Reported by: php at sygmoral dot com
Summary: Issue in automatic $_POST array handling
-Status: Open
+Status: Feedback
Type: Bug
Package: Arrays related
Operating System: Debian
PHP Version: 5.4.12
Block user comment: N
Private report: N
New Comment:
PHP won't allow variables name to contains "[", "." etc , so I think this
is
really a narrow usage.
but, however I do believe there is a bug.
a patch will be attached. but I need to ask someone else's opinion before commit
it.
thanks
Previous Comments:
------------------------------------------------------------------------
[2013-02-28 19:45:57] php at sygmoral dot com
Thank you for your reaction!
But no: I did in fact mean what I wrote. I realise it's a strange data structure, so
here's a short explanation for it: the 'save' array holds a collection of html form
elements that are not yet to be submitted, but should be saved temporarily into some other set of
memory, so that upon the next visit, those temporary values can be easily inserted into the
displayed form, without having been submitted. In other words, it's for a form that remembers
its state throughout visits.
So I send an object containing the name-value pairs in the form, and send that over POST. In the
example used here, this results in one or more name-value pairs that are saved into the save array,
as save['line[]'] = value.
And that is the situation that triggers this bug, as in my original post. I'm sure there are
other ways to achieve what I want, but I figured I'd report it since this does not look as if
it's intended.
Note that the example is a simplification of my application, where multiple 'single' and
'array' values are saved.
------------------------------------------------------------------------
[2013-02-28 18:22:57] reeze@php.net
"post_data = {'save[line[]]':'A line with text'}â
do you mean post_data = {'save[line][]':'A line with text'} ?
^^
is this you intention?
array(
'save' =>
['line' =>
['A line with text', 'maybe more lines']
]
); ?
------------------------------------------------------------------------
[2013-02-28 16:09:49] php at sygmoral dot com
Description:
------------
Php automatically puts POSTed name-value pairs with names ending in [] into arrays. Very handy
feature! However, I notice issues when more of those square brackets are encountered.
If I send a name like save[line[]], then save will be an array and the
first key in it will be line[, instead of line[]. It's not that I
expect a second level of arrays - just that it doesn't strangely remove that last bracket.
So suppose we have the tiny php script below, and I send this with e.g. jquery:
post_data = {'save[line[]]':'A line with text'}
Effectively, the raw POST data being sent is:
save%5Bline%5B%5D%5D=A+line+with+text
Test script:
---------------
print_r(
$_POST['save']
);
Expected result:
----------------
POST: Array
(
[line[]] => A line with text
)
Actual result:
--------------
POST: Array
(
[line[] => A line with text
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64325&edit=1
Thread (9 messages)