|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81001 var_export/serialize changes array key type
Submitted: 2021-04-30 00:40 UTC Modified: 2021-04-30 00:48 UTC
From: smokey101stair at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Ubuntu 20.04
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: smokey101stair at gmail dot com
New email:
PHP Version: OS:


 [2021-04-30 00:40 UTC] smokey101stair at gmail dot com
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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-30 00:48 UTC]
-Status: Open +Status: Not a bug
 [2021-04-30 00:48 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

That is the behavior of arrays as a whole, not of var_export() or serialize().
> 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.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 17:04:04 2022 UTC