Bug #75580 [Opn->Nab]: array_column and Traversable objects

From: Date: Mon, 27 Nov 2017 12:08:13 +0000
Subject: Bug #75580 [Opn->Nab]: array_column and Traversable objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212746@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75580&edit=1 ID: 75580 Updated by: requinix@php.net Reported by: thisnicknamewasfree at gmail dot com Summary: array_column and Traversable objects -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: All PHP Version: 7.1.12 Block user comment: N Private report: N New Comment: 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. http://php.net/mailing-lists.php Previous Comments: ------------------------------------------------------------------------ [2017-11-27 11:51:38] thisnicknamewasfree at gmail dot com <?php $dom = new \DomDocument; $dom->loadHTML('<span>ONE</span><span>TWO</span>'); $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 11:31:40] requinix@php.net 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:21:22] thisnicknamewasfree at gmail dot com Description: ------------ 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75580&edit=1

« previous php.bugs (#212746) next »