Bug #81001 [Opn->Nab]: var_export/serialize changes array key type

From: Date: Fri, 30 Apr 2021 00:48:16 +0000
Subject: Bug #81001 [Opn->Nab]: var_export/serialize changes array key type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233623@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81001&edit=1 ID: 81001 Updated by: requinix@php.net Reported by: smokey101stair at gmail dot com Summary: var_export/serialize changes array key type -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Ubuntu 20.04 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That is the behavior of arrays as a whole, not of var_export() or serialize(). https://www.php.net/manual/en/language.types.array.php > The key can either be an int or a string. The value can be of any type. > > Additionally the following key casts will occur: > * Strings containing valid decimal ints, unless the number is preceded by a + > sign, will be cast to the int type. E.g. the key "8" will actually be stored > under 8. On the other hand "08" will not be cast, as it isn't a valid decimal > integer. Previous Comments: ------------------------------------------------------------------------ [2021-04-30 00:40:57] smokey101stair at gmail dot com Description: ------------ When using var_export() or serialize() to export an array that has base 10 numeric strings as array keys, those keys are changed to integers. Keys that are strings should stay strings. If this is intended behavior, it should be documented that array key types are subject to change. Test script: --------------- https://3v4l.org/1RsHW ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81001&edit=1

« previous php.bugs (#233623) next »