Bug #53432 [Opn->Ver]: Assignment via string index access on an empty string converts to array
| From: | jani@php.net | Date: | Wed, 01 Dec 2010 14:17:03 +0000 |
| Subject: | Bug #53432 [Opn->Ver]: Assignment via string index access on an empty string converts to array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156623@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53432&edit=1
ID: 53432
Updated by: jani@php.net
Reported by: phplists at stanvassilev dot com
Summary: Assignment via string index access on an empty
string converts to array
-Status: Open
+Status: Verified
Type: Bug
-Package: Unknown/Other Function
+Package: Scripting Engine problem
-Operating System: All
+Operating System: *
-PHP Version: 5.2.14
+PHP Version: 5.*
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/bug.php?id=53432&edit=1