php.net |  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
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: phpbugs at personal dot formauri dot es
New email:
PHP Version: OS:

 

 [2013-07-16 04:26 UTC] phpbugs at personal dot formauri dot es
Description:
------------
When explaining array index types, the docs for the array type http://www.php.net/manual/en/language.types.array.php 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.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-25 16:06 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-10-25 16:06 UTC] krakjoe@php.net
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 22:01:41 2021 UTC