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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 37 = ?
Subscribe to this entry?

 
 [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: Fri May 10 22:01:32 2024 UTC