php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53432 Assignment via string index access on an empty string converts to array
Submitted: 2010-12-01 04:19 UTC Modified: 2010-12-01 15:16 UTC
Votes:8
Avg. Score:2.9 ± 1.3
Reproduced:7 of 8 (87.5%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: phplists at stanvassilev dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.* OS: *
Private report: No CVE-ID:
 [2010-12-01 04:19 UTC] phplists at stanvassilev dot com
Description:
------------
The title/code says it all. Once a variable is a string, using array access should 
mean char access, but this is not maintained for empty strings, while it's 
maintained for non-empty strings.

Test script:
---------------
$a = ''; // empty string
$a[10] = 'a';
echo $a; // "Array"

$b = ' '; // non empty string
$b[10] = 'b';
echo $b; // "          b"

Expected result:
----------------
"          a"
"          b"

Actual result:
--------------
"Array"
"          b"

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-01 04:33 UTC] phplists at stanvassilev dot com
-Summary: String index access on empty string converts to array +Summary: Assignment via string index access on an empty string converts to array
 [2010-12-01 04:33 UTC] phplists at stanvassilev dot com
I want to note, I realize when the variable is undefined, null, false, array is 
the expected end result, but a string is already signifying explicitly the intent 
of the programmer.

While PHP is a language with loose typing, it's not as loose as to convert scalars 
to arrays and back, despite a set value.
 [2010-12-01 15:16 UTC] jani@php.net
-Status: Open +Status: Verified -Package: Unknown/Other Function +Package: Scripting Engine problem -Operating System: All +Operating System: * -PHP Version: 5.2.14 +PHP Version: 5.*
 [2016-06-04 17:20 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=945a83103de8fbba66bdf643c4701263854c0056
Log: Fixed bug #53432
 [2016-06-04 17:20 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Wed Jun 29 19:01:49 2016 UTC