|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75580 array_column and Traversable objects
Submitted: 2017-11-27 11:21 UTC Modified: 2017-11-27 12:08 UTC
From: thisnicknamewasfree at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.1.12 OS: All
Private report: No CVE-ID: None
 [2017-11-27 11:21 UTC] thisnicknamewasfree at gmail dot com
PHP 7.0+ supports both arrays and array of objects for array_column, However it's not true for array of Traversable objects and looks like a bug.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-27 11:31 UTC]
-Status: Open +Status: Feedback
 [2017-11-27 11:31 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

An array of Traversables?
 [2017-11-27 11:51 UTC] thisnicknamewasfree at gmail dot com
-Status: Feedback +Status: Open
 [2017-11-27 11:51 UTC] thisnicknamewasfree at gmail dot com

$dom = new \DomDocument;

$xpath = new \DomXPath($dom);     # $xpath -> \DOMXPath
$nodes = $xpath->query('//span'); # $nodes -> \DOMNodeList

# this works:

foreach ($nodes as $node)
	echo $node->nodeValue; # \DOMElement

# this not:

array_column($nodes, 'nodeValue');

 [2017-11-27 12:08 UTC]
-Status: Open +Status: Not a bug
 [2017-11-27 12:08 UTC]
As is documented, array_column (and other array_* functions) take arrays as inputs. $nodes is not an array. Use iterator_to_array() to convert.

If you want something changed on the PHP side then you should raise the subject on the internals mailing list because whatever it is likely won't be trivial.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Apr 10 04:01:23 2020 UTC