Bug #76589 [Opn->Nab]: array_column should error when value is not castable to array key
| From: | cmb@php.net | Date: | Sun, 18 Nov 2018 00:10:35 +0000 |
| Subject: | Bug #76589 [Opn->Nab]: array_column should error when value is not castable to array key | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218006@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76589&edit=1
ID: 76589
Updated by: cmb@php.net
Reported by: nobots dot nospam at example dot org
Summary: array_column should error when value is not castable
to array key
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
PHP Version: 7.3.0alpha3
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Since bug #68553 has been fixed, the index keys are almost treated
like the usual array key casts[1] (the sole exception being
objects which support being cast to string are also allowed), so
I'd say that this is not a bug.
@ a at b dot c dot de
I've seen quite a lot of useful comments on bug tickets from you.
Isn't it time to reveal your identity? At least, please don't use
domain names occupied by others (unless they're covered by RFC
2606/6761).
[1] <http://www.php.net/manual/en/language.types.array.php#example-56>
Previous Comments:
------------------------------------------------------------------------
[2018-07-10 22:48:43] 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;".
------------------------------------------------------------------------
[2018-07-07 04:49:55] example at example dot org
sorry for that, someone mentioned it and i thought nobody had reported it already
------------------------------------------------------------------------
[2018-07-06 15:40:52] requinix@php.net
Why did you make this second bug report?
------------------------------------------------------------------------
[2018-07-06 14:35:12] cmb@php.net
Related to bug #76587.
------------------------------------------------------------------------
[2018-07-06 14:17:36] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76589&edit=1