php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #44808 Accessing string offsets (array notation)
Submitted: 2008-04-23 14:11 UTC Modified: 2008-11-05 17:17 UTC
From: florian dot ember at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Windows XP
Private report: No CVE-ID: None
 [2008-04-23 14:11 UTC] florian dot ember at gmail dot com
Description:
------------
While messing around with the feature mentioned in the summary, I came across some undocumented results and/or bugs which should be documented (or fixed respectively).

Offsets
- When using an out of range offset, the string is padded with spaces.
- When using a floating point number as offset, it is *always* rounded down.
- When using an illegal type (such as an array) as offset, a warning is emitted and 0 is assumed.
- When using a negative offset, PHP reports an uninitialized offset in read context, but reports an illegal offset in write context.

Insert strings
- When using a string which length is greater than 1, only the first character is used. (Fairly obvious but not documented)
- When using a string which length is 0 ("", that is), a \0 character is inserted at that position instead.

The last result is the strangest one. Might be a bug.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-05 17:17 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"
Writing to an out of range offset pads the string with spaces.
Non-integer types are converted to integer.
Illegal offset type emits E_NOTICE.
Negative offset emits E_NOTICE in write but reads empty string.
Only the first character of an assigned string is used.
Assigning empty string assigns NUL byte.
"
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 04:00:01 2026 UTC