Bug #65265 [NEW]: Docs about when an array index is a string or an integer unclear or wrong
| From: | phpbugs at personal dot formauri dot es | Date: | Tue, 16 Jul 2013 04:26:21 +0000 |
| Subject: | Bug #65265 [NEW]: Docs about when an array index is a string or an integer unclear or wrong | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-10079@lists.php.net to get a copy of this message | ||
From: phpbugs at personal dot formauri dot es
Operating system: Irrelevant
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Bug
Bug description:Docs about when an array index is a string or an integer unclear or wrong
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=65265&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65265&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65265&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65265&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65265&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65265&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65265&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65265&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65265&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65265&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65265&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65265&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65265&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65265&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65265&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65265&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65265&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65265&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65265&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65265&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65265&r=mysqlcfg