php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81508 http_build_query returns empty string given ArrayIterator as input
Submitted: 2021-10-05 15:28 UTC Modified: 2021-10-05 19:01 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mintobit at gmail dot com Assigned:
Status: Open Package: URL related
PHP Version: 7.4.24 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mintobit at gmail dot com
New email:
PHP Version: OS:

 

 [2021-10-05 15:28 UTC] mintobit at gmail dot com
Description:
------------
Have not found anything related here https://www.php.net/manual/en/migration74.incompatible.php. Would appreciate if somebody can explain why this happened: wondering if this is expected and should be documented.

Test script:
---------------
<?php

$array = [
    ['ids' => [1,2,3,4]],
    ['key' => 1]
];

var_dump(http_build_query(new ArrayIterator($array)));

Expected result:
----------------
string(92) "0%5Bids%5D%5B0%5D=1&0%5Bids%5D%5B1%5D=2&0%5Bids%5D%5B2%5D=3&0%5Bids%5D%5B3%5D=4&1%5Bkey%5D=1"

Actual result:
--------------
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-05 16:00 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-10-05 16:00 UTC] requinix@php.net
> Calling get_object_vars() on an ArrayObject instance will now always return the
> properties of the ArrayObject itself (or a subclass). Previously it returned the
> values of the wrapped array/object unless the ArrayObject::STD_PROP_LIST flag
> was specified.
>
> Other affected operations are:
>
> * ReflectionObject::getProperties()
> * reset(), current(), etc. Use Iterator methods instead.
> * Potentially others working on object properties as a list, e.g. array_walk().

The third bullet point is the one that affects http_build_query().
 [2021-10-05 18:33 UTC] salathe@php.net
-Status: Not a bug +Status: Open
 [2021-10-05 18:33 UTC] salathe@php.net
> Calling get_object_vars() on an ArrayObject instance will now ...

The quoted section from the migration guide references ArrayObject, but makes no mention that the change also applies to ArrayIterator.
 [2021-10-05 19:01 UTC] requinix@php.net
Ah, yup, that is exactly what it says. My brain likes to bundle them together.

Presumably it's the same underlying change affecting both.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Nov 29 19:03:12 2021 UTC