php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59265 $extra_parameters can't accept multi dimensional arrays
Submitted: 2010-06-16 11:31 UTC Modified: 2013-02-18 00:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: z at orbus dot fr Assigned: datibbaw (profile)
Status: No Feedback Package: oauth (PECL)
PHP Version: 5.2.13 OS: Debian/Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-06-16 11:31 UTC] z at orbus dot fr
Description:
------------
When you send a multidimensional array to fetch method, it will fail to convert it as a string to send to the server.

Reproduce code:
---------------
$oauth->fetch($api_url, array('one' => array('two' => array('three'))), OAUTH_HTTP_METHOD_POST);


Expected result:
----------------
Server should receive:
one[two][]=three

Actual result:
--------------
Server is receiving:
one=Array

And there's a 'Notice:  Array to string conversion' in client code.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-16 12:39 UTC] datibbaw@php.net
Multi-dimensional arrays should be passed as:

array('arr[]' => array(1,2,3))

Produces:
arr[]=1&arr[]=2&arr[]=3
 [2010-06-17 10:33 UTC] z at orbus dot fr
This is not really a useful solution... I think that fetch should accept any multi-dimensional array in $extra_parameters and do all the intelligent stuff itself.
 [2010-06-17 11:06 UTC] datibbaw@php.net
First, how would you know whether to send 'arr=1&arr=2' or 'arr[]=1&arr[]=2' ? Not all servers behave like PHP.

Second, which service are you consuming that requires passing a multi-dimensional array?
 [2010-06-17 11:20 UTC] jawed@php.net
I agree with datibbaw, it's not clear how we'd support this 
beyond PHP.

If the goal is to pass multidimensional values you should 
use a format which properly supports them, ie XML/JSON.

Can you give us some information around which API you are 
using which requires this?

- JJ
 [2010-06-17 11:25 UTC] z at orbus dot fr
I'm just expecting that OAuth::fetch will behave like other PHP functions, eg. http_build_query is doing the right thing:

$array = array('one' => array('two' => array('three')));
echo http_build_query($array, null, '&');
// Outputs: one[two][0]=three
 [2010-06-17 19:49 UTC] datibbaw@php.net
Leaving this open to fix the provider issues, but after that I'm closing it.

Unless there's a public API that requires passing multidimensional arrays, this is not considered a bug, though it could be mentioned in the manual I suppose.
 [2010-06-18 04:57 UTC] z at orbus dot fr
We were going to release our public API this week but when we found this bug we figured we'd better wait and find a solution before consumer developers send bugs.

I think we will implement an option server-side an option for sending either POST arrays or JSON (which is btw the best imho), and we'll write in the documentation what kind of POST arrays we accept (and it'll be up to the developer to send something we'll understand).

What is a real bug here, is that OAuth::fetch is throwing a array to string error notice and sending to the server incomplete datas (like index=Array, weird). It should either throw an exception or do something like http_build_query, but sending the 'Array' string to the server is neither elegant nor useful for developers.
 [2011-01-15 13:36 UTC] jawed@php.net
I agree, I think you should use a format which is more fit for 
the data hierarchy you are trying to represent (+1 on JSON).

- JJ
 [2011-03-01 22:06 UTC] elvis at elvis dot eti dot br
Dear friends,

Any app using Rails as backend would need to send a 
multidimensional array in POST and PUT requests.

For example, if you check the code in 2.2.2 here:
http://guides.rubyonrails.org/v2.3.8/layouts_and_rendering.h
tml#using-render
... you'll see that Rails expects an array with a 'book' 
index, containing another array. If we use nested 
attributes, we can have even another array inside it!

In other words, anyone trying to use Rails + OAuth in the 
backend wouldn't be able to use PECL::OAuth::fetch() to send 
data to the server in other format other than json (I had 
troubles using XML!).

Hope this helps to clarify the problem posted here.
 [2011-03-01 23:00 UTC] jawed@php.net
Thanks for the info - JSON does seem to be the best choice for this use 
case.

- JJ
 [2011-03-02 21:36 UTC] datibbaw@php.net
Think I still have a fix lying around to throw an exception 
whenever a multi-dimensional array is passed ... will look for 
it tonight.
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Feb 18 19:01:28 2020 UTC