Bug #53432 [Opn]: Assignment via string index access on an empty string converts to array

From: Date: Wed, 01 Dec 2010 03:33:34 +0000
Subject: Bug #53432 [Opn]: 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-156610@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
 User updated by:    phplists at stanvassilev dot com
 Reported by:        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
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   All
 PHP Version:        5.2.14
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#156610) next »