php.net |  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.
Password:
Status:
Package:
Bug Type:
Summary:
From: smokey101stair at gmail dot com
New email:
PHP Version: OS:

 

 [2021-04-30 00:40 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-30 00:48 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-04-30 00:48 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC