php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76589 array_column should error when value is not castable to array key
Submitted: 2018-07-06 14:17 UTC Modified: 2018-07-06 15:40 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nobots dot nospam at example dot org Assigned:
Status: Open Package: Arrays related
PHP Version: 7.3.0alpha3 OS:
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: nobots dot nospam at example dot org
New email:
PHP Version: OS:

 

 [2018-07-06 14:17 UTC] nobots dot nospam at example dot org
Description:
------------
array_column should error when value is not castable to array key without loss of data

$a = [
    [ 'foo' => 777.5 ],
];

array_column($a, 'foo', 'foo');

is an error because float cannot be used as array key

------------

also it should error if the index already exists and is being overwritten

$a = [
    [ 'foo' => 777, "hi" => 1 ],
    [ 'foo' => 777, "hi" => 2 ],
];

the index 777 is written twice and the original value is lost

------------

and this is certainly a bug https://3v4l.org/WhUmh


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-06 14:35 UTC] cmb@php.net
Related to bug #76587.
 [2018-07-06 15:40 UTC] requinix@php.net
Why did you make this second bug report?
 [2018-07-07 04:49 UTC] example at example dot org
sorry for that, someone mentioned it and i thought nobody had reported it already
 [2018-07-10 22:48 UTC] a at b dot c dot de
I wouldn't say that the second behaviour (values are discarded if keys are repeated) is a bug.

The same behaviour is seen in every other situation where array keys can (try to) be repeated (e.g. array_merge, array_flip, array_combine, array_change_key_case, even "$a['foo'] = 1; $a['foo'] = 2;".
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Oct 18 19:01:26 2018 UTC