php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69413 Warning in array_count_values() about array values not being string/int
Submitted: 2015-04-09 23:41 UTC Modified: 2015-04-10 01:53 UTC
From: berdir@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2015-04-09 (Git) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: berdir@php.net
New email:
PHP Version: OS:

 

 [2015-04-09 23:41 UTC] 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.





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-09 23:47 UTC] 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-10 00:45 UTC] 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-10 01:30 UTC] danack@php.net
-Status: Open +Status: Verified
 [2015-04-10 01:30 UTC] 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 01:53 UTC] danack@php.net
-Package: Arrays related +Package: Scripting Engine problem -Assigned To: +Assigned To: dmitry
 [2015-04-10 07:49 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=94bea670de40c937d5926839d52dc262750921f4
Log: Fix bug #69413
 [2015-04-10 07:49 UTC] nikic@php.net
-Status: Verified +Status: Closed
 [2016-07-20 11:39 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=94bea670de40c937d5926839d52dc262750921f4
Log: Fix bug #69413
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC