Bug #69413 [Com]: Warning in array_count_values() about array values not being string/int

From: Date: Thu, 09 Apr 2015 23:47:36 +0000
Subject: Bug #69413 [Com]: 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-191925@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 Comment by: berdir@php.net Reported by: berdir@php.net Summary: Warning in array_count_values() about array values not being string/int Status: Open Type: Bug Package: Arrays related Operating System: Linux PHP Version: master-Git-2015-04-09 (Git) Block user comment: N Private report: N New Comment: 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) "" } Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#191925) next »