Bug #72031 [NEW]: array_column() against an array of objects discards all values matching null

From: Date: Fri, 15 Apr 2016 13:46:52 +0000
Subject: Bug #72031 [NEW]: array_column() against an array of objects discards all values matching null
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200568@lists.php.net to get a copy of this message
From: mark at lange dot demon dot co dot uk Operating system: All PHP version: 7.0.6RC1 Package: Unknown/Other Function Bug Type: Bug Bug description:array_column() against an array of objects discards all values matching null Description: ------------ PHP7 extended array_column() to support reading a column of property values from an array of objects. However, if the property contains a value that loose-equates to null, that entry is not returned in the resulting array. Applies to all PHP7 releases; http://lxr.php.net/xref/PHP_7_0/ext/standard/array.c#3569 appears to be the cause of the bug The code test script demonstrates this problem. Expected result is an array containing [-1,0,1,2,null,true,false,'abc',''] Actual result is an array containing [-1,1,2,true,'abc'] The 0, null, false and empty string values are all discarded Test script: --------------- class myObj { public $prop; public function __construct($prop) { $this->prop = $prop; } } $objects = [ new myObj(-1), new myObj(0), new myObj(1), new myObj(2), new myObj(null), new myObj(true), new myObj(false), new myObj('abc'), new myObj(''), ]; var_dump(array_column($objects, 'prop')); Expected result: ---------------- array(9) { [0]=> int(-1) [1]=> int(0) [2]=> int(1) [3]=> int(2) [4]=> null [5]=> bool(true) [6]=> bool(false) [7]=> string(3) "abc" [8]=> string(0) "" } [-1,0,1,2,null,true,false,'abc',''] Actual result: -------------- array(5) { [0]=> int(-1) [1]=> int(1) [2]=> int(2) [3]=> bool(true) [4]=> string(3) "abc" } -- Edit bug report at https://bugs.php.net/bug.php?id=72031&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72031&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72031&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72031&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72031&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72031&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72031&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72031&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72031&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72031&r=support Expected behavior: https://bugs.php.net/fix.php?id=72031&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72031&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72031&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72031&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72031&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72031&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72031&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72031&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72031&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72031&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72031&r=mysqlcfg

« previous php.bugs (#200568) next »