Edit report at https://bugs.php.net/bug.php?id=64325&edit=1

 ID:                 64325
 Updated by:         re...@php.net
 Reported by:        php at sygmoral dot com
 Summary:            Issue in automatic $_POST array handling
 Status:             Feedback
 Type:               Bug
 Package:            *General Issues
 Operating System:   Debian
 PHP Version:        5.4.12
 Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

The attached patch may break form like: foo[bar][index]=test

after some research, this seems a undocumented behavior but not a bug.

only the field name `save` can not have '[' and other special chars.
the subkeys didn't required to be a legal variable name but '[]' are special
chars.


Previous Comments:
------------------------------------------------------------------------
[2013-03-01 03:29:43] larue...@php.net

The following patch has been added/updated:

Patch Name: bug64325.patch
Revision:   1362108583
URL:        
https://bugs.php.net/patch-display.php?bug=64325&patch=bug64325.patch&revision=1362108583

------------------------------------------------------------------------
[2013-03-01 03:29:02] larue...@php.net

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

------------------------------------------------------------------------
[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] re...@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

Reply via email to