Bug #69413 [NEW]: Warning in array_count_values() about array values not being string/int
| From: | berdir@php.net | Date: | Thu, 09 Apr 2015 23:41:31 +0000 |
| Subject: | Bug #69413 [NEW]: Warning in array_count_values() about array values not being string/int | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191924@lists.php.net to get a copy of this message | ||
From: berdir
Operating system: Linux
PHP version: master-Git-2015-04-09 (Git)
Package: Arrays related
Bug Type: Bug
Bug description:Warning in array_count_values() about array values not being string/int
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 bug report at https://bugs.php.net/bug.php?id=69413&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69413&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69413&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69413&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69413&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69413&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69413&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69413&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69413&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69413&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69413&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69413&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69413&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69413&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69413&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69413&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69413&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69413&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69413&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69413&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69413&r=mysqlcfg