|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65265 Docs about when an array index is a string or an integer unclear or wrong
Submitted: 2013-07-16 04:26 UTC Modified: 2013-10-25 16:06 UTC
From: phpbugs at personal dot formauri dot es Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
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:
Solve the problem:
35 + 29 = ?
Subscribe to this entry?

 [2013-07-16 04:26 UTC] phpbugs at personal dot formauri dot es
When explaining array index types, the docs for the array type say:

'Strings containing valid integers will be cast to the integer 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.'

Taken literally, that paragraph would imply that the key '07', which is a valid integer, will be cast to the integer 7. However, that's not the case. $a['07'] does not reference the same element as $a[7].

The last qualification of 'decimal' integer gives a hint of what the actual intention of that paragraph was. It's possible to change the wording to "Strings containing valid decimal integers..." and to change the example to use 7 instead of 8, to leave it clearer how that excludes numbers with leading zeros no matter their validity as octal numbers. But that's not accurate enough either. Formally, +3 is a valid decimal integer, yet $a['+3'] doesn't reference the same element as $a[3].

It could say that the key is only cast to integer when a conversion of the string to integer and back to a decimal string gives the original string. The wording can become somewhat confusing though, just as the former statement is.

In past the wording seemed to be that if it's the standard representation of an integer then it's cast to integer. That seems more accurate than the current wording, yet still a bit confusing because there's no definition of standard representation.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-25 16:06 UTC]
-Status: Open +Status: Not a bug
 [2013-10-25 16:06 UTC]
Taken literally, and read correctly, that paragraph implies what happens with "07", which is NOT a valid decimal, is expected; you must therefore have misread the words of the sentence in question, it is quite clear.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 22 21:03:38 2021 UTC