Bug #69413 [Ver->Csd]: Warning in array_count_values() about array values not being string/int
| From: | nikic@php.net | Date: | Fri, 10 Apr 2015 07:49:41 +0000 |
| Subject: | Bug #69413 [Ver->Csd]: Warning in array_count_values() about array values not being string/int | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191931@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69413&edit=1
ID: 69413
Updated by: nikic@php.net
Reported by: berdir@php.net
Summary: Warning in array_count_values() about array values
not being string/int
-Status: Verified
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: master-Git-2015-04-09 (Git)
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=94bea670de40c937d5926839d52dc262750921f4
Log: Fix bug #69413
Previous Comments:
------------------------------------------------------------------------
[2015-04-10 01:30:46] danack@php.net
Found a simple repo script. It appears to break when one of the elements in the array is a
reference.
<?php
$foo = [
'en' => '',
'fr' => 'fr'
];
$bar = [
'de' => 'de'
];
$bar[] = $foo['en'];
var_dump(array_count_values($foo));
$bar[] = &$foo['fr'];
var_dump(array_count_values($foo));
------------------------------------------------------------------------
[2015-04-10 00:45:19] danack@php.net
Hi Berdir,
Not sure if it will actually help, but if you can dump the var with debug_zval_dump() - http://php.net/manual/en/function.debug-zval-dump.php
it might provide some info.
cheers
Dan
------------------------------------------------------------------------
[2015-04-09 23:47:36] berdir@php.net
To reproduce, install D8 (see linked issue, you need gd, curl and some other extensions), install
the language module and go to admin/config/regional/language/detection/url, save the form.
Doesn't matter if you enter something or not.
var_dump() output:
array(1) { ["en"]=> string(0) "" }
------------------------------------------------------------------------
[2015-04-09 23:41:30] berdir@php.net
Description:
------------
This is part of our efforts to get Drupal 8 green on PHP 7, see https://www.drupal.org/node/2454439.
This might be related to https://bugs.php.net/bug.php?id=69371, which was a
somewhat similar php bug that we found (Similar as in, arrays/array functions behaving strangely).
We have a code line like this:
array_count_values($form_state->getValue('prefix'))
This displays:
array_count_values(): Can only count STRING and INTEGER
values! Warning NegotiationUrlForm.php 183 Drupal\language\Form\NegotiationUrlForm->validateForm()
But the array definitely is valid:
Array
(
[en] =>
[fr] => fr
)
(en is an empty string, type string)
Looping over the array works, accessing the keys works. Trying the same with that array works:
$ php7 -r '$array = array("en" => "", "fr" =>
"fr"); var_dump(array_count_values($array));'
array(2) {
[""]=>
int(1)
["fr"]=>
int(1)
}
Re-creating the array with the same values works:
$prefix = ['en' => $form_state->getValue('prefix')['en'],
'fr' => $form_state->getValue('prefix')['fr']];
$count = array_count_values($prefix);
So, similar in the other issue, the array or one of those values seems to be in a weird state.
I've tracked down the place where this warning is displayed to https://github.com/php/php-src/blob/master/ext/standard/array.c#L3017.
If anyone can tell me what to put there to debug the content and type of entry, then I'm more
than happy to try that.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69413&edit=1