Bug #53432 [Ver->Csd]: Assignment via string index access on an empty string converts to array
Edit report at https://bugs.php.net/bug.php?id=53432&edit=1
ID: 53432
Updated by: nikic@php.net
Reported by: phplists at stanvassilev dot com
Summary: Assignment via string index access on an empty
string converts to array
-Status: Verified
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.*
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=945a83103de8fbba66bdf643c4701263854c0056
Log: Fixed bug #53432
Previous Comments:
------------------------------------------------------------------------
[2016-02-15 13:09:43] francois@php.net
Related To: Bug #70097
------------------------------------------------------------------------
[2010-12-01 04:33:28] 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 04:19:40] 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"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53432&edit=1
Thread (5 messages)