php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #745 <input type=image> and array variables
Submitted: 1998-09-14 05:47 UTC Modified: 2005-05-03 19:16 UTC
Votes:31
Avg. Score:2.8 ± 1.1
Reproduced:4 of 14 (28.6%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: be at shonline dot de Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 4.3.0-dev 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: be at shonline dot de
New email:
PHP Version: OS:

 

 [1998-09-14 05:47 UTC] be at shonline dot de
I have for example

<input type=image name="foo[123]">

in a form. Then the receiving script does
not have

$foo_x[123] and $foo_y[123]

in its namespace.

It has only $foo[123] containg the value
of what should be $foo_y[123]

Boris

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-10 12:30 UTC] jimw@php.net
looks like this was never addressed, refiling against 4.0.
 [2001-12-12 14:33 UTC] zak@php.net
Maybe we should just make $foo_x[123] and $foo_y[123] 
available in addition to $foo[123]? That should keep BC 
and still do things right, though we might want to change 
the value of $foo[123] to something like 'x,y' instead of 
just y???


 [2001-12-12 14:45 UTC] hholzgra@php.net
i'd like to have $whatever[...][...][x] and $whatever[...][...][y] in all cases, maybe 
with ini switches for old, new or both ...
 [2001-12-12 15:02 UTC] zak@php.net
Personally, I would rather avoid adding configuration 
directives for something as small as this! :)

 [2002-07-01 08:49 UTC] sniper@php.net
Raw post data and resulting variables:

foo%5B123%5D.x=5&foo%5B123%5D.y=10
Array ( [foo] => Array ( [123] => 10 ) ) 


bar%5B%5D.x=5&bar%5B%5D.y=10
Array ( [bar] => Array ( [0] => 5 [1] => 10 ) )


foobar.x=5&foobar.y=10
Array ( [foobar_x] => 5 [foobar_y] => 10 ) 

Not very consistent..


 [2002-12-02 18:18 UTC] pollita@php.net
Given raw post data of: foo%5B123%5D.x=5&foo%5B123%5D.y=10

I disagree with having the script engine turn that into:
[foo] => Array ( 
  [123] => Array (
    [x] => 5
    [y] => 10
  )    
) 
as this would break backward compatability (though I doubt many scripts are using this to be honest).

There are two sensical solution that pop into my head:
#1)
[foo] => Array ( 
  [123]   => 10    // For BC
  [123.x] => 5
  [123.y] => 10
) 

From an engine stand point all this says is "if the ] is not at the end of the varname, move it there."

However, I don't like this idea either.  While it makes the data accessable without breaking anything, it's just plain ugly.

#2)
[foo] => Array ( 
  [123]   => 10    // For BC
) 
[foo_x] => Array ( 
  [123]   => 5
) 
[foo_y] => Array ( 
  [123]   => 10
) 

From an engine stand point all this says is "if there is a [] block which is not at the end of the varname, make one copy of the var with the end truncated, then move the [] block to the end and export that varname as well."
i.e.: foo[123]bar => foo[123] && foobar[123]

And come to that it would want to include cases where there is non [] text between [] blocks:
i.e.: foo[123]bar[456] => foo[123][456] && foobar[123][456]
or possibly...
foo[123]bar[456] => foo[123][456] && foo[123][bar][456]

I can get behind this approach... At least in principal... But I don't believe in its need enough to work on it unless it gets a several +1s.  It also has the disadvantage of allowing scripters to get used to naming their form elements incorrectly. (Not that the image example is incorrect, per se, but it's a special case as the browser modifies the name beyond the control of the designer).
 [2003-05-23 21:58 UTC] sniper@php.net
Little bit of thinking and it's obvious.
Instead of using name="foo[123]", you should use name="foo[123][]" which will end up being a full array:

Array
(
    [blah] => Array
        (
            [123] => Array
                (
                    [0] => 12
                    [1] => 16
                )

        )

)

To access the values:

$foo[123][0] == x value
$foo[123][1] == y value


Or just do not define the index and use name="foo[]" and
you'll get:

Array
(
    [blah] => Array
        (
            [0] => 14
            [1] => 15
        )

)

There's no point in 'fixing' this in PHP.



 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 19:01:29 2024 UTC