|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #31303 treating a string like a regular array leads to a fatal offset
Submitted: 2004-12-26 08:07 UTC Modified: 2005-04-11 09:51 UTC
From: schmad at miller-group dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.3 OS: Mac OS X 10.3.7
Private report: No CVE-ID: None
 [2004-12-26 08:07 UTC] schmad at miller-group dot net
Using array functions on a string like count() or 
unset() results in fatal offset errors which were not 
encountered in 4.3.x code.

Reproduce code:
$link = 'bla';
//In 4.x: No Error

$link = '';
//In 4.x: No Error

Expected result:
$link = 'bla';
//In 4.x: No Error

$link = '';
//In 4.x: No Error

Actual result:
$link = 'bla';
//Outputs: Fatal error: Cannot unset string offsets in 

$link = '';
//Outputs: Fatal error: Cannot use string offset as an 
array in ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-26 11:35 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is expected, and not a bug. It doesn\'t make sense to do this at all either.
 [2004-12-26 20:08 UTC] schmad at miller-group dot net
Perhaps it isn't a bug, but it does break backward 
compatibility with 4.3.
 [2004-12-26 20:29 UTC]
THen it should be documented.
 [2004-12-26 22:29 UTC]
 [2004-12-29 16:43 UTC]
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.

I believe it is already documented in Backward Incompatible Changes under Migrating from PHP 4 to PHP 5 in the sentence "Illegal use of string offsets causes E_ERROR instead of E_WARNING."

However, I have added this to the String Type chapter: "However, this syntax is deprecated as of PHP 4 and produces fatal error in PHP 5."
 [2004-12-29 17:08 UTC]
You changed the wrong thing, $string[0] still works.
et@edea:~$ php -r '$foo = "abc"; var_dump($foo[0]);'
string(1) "a"
Also, the second example doesn't seem to produce a fatal error.
et@edea:~$ php -r '$link = ""; var_dump(count($link["two"]));'

Notice: Uninitialized string offset:  0 in Command line code on line 1
et@edea:~$ php -v
PHP 5.1.0-dev (cli) (built: Dec 28 2004 20:03:13)

 [2004-12-29 20:47 UTC]
Yep, please revert the change at 'language.types.string'.
PHP 5 only causes a fatal error whith 'unset($string["a"]);'

 [2004-12-30 09:48 UTC]
Reverted, sorry. I'm not sure where to add this piece of information so I'm leaving this bug open for someone else :-).
 [2005-04-11 09:51 UTC]
This behavior isn't limited to [] either, {} is affected the same way. But anyway, using unset() on strings like this has no use whatsoever.

An example has now been added to migration5.xml so this bug is closed.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC