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

From: Date: Fri, 14 Jul 2017 16:55:47 +0000
Subject: Bug #53432 [Com]: 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-210059@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53432&edit=1

 ID:                 53432
 Comment by:         christian at deligant dot net
 Reported by:        phplists at stanvassilev dot com
 Summary:            Assignment via string index access on an empty
                     string converts to array
 Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        5.*
 Block user comment: N
 Private report:     N

 New Comment:

Bug is still present on 7.0.18 (ubuntu 16-04 vanilla)

the only difference is that the string comes from a database but is definitely an empty string
('') nothing more


Previous Comments:
------------------------------------------------------------------------
[2016-07-20 11:30:46] davey@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:37] 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-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)

« previous php.bugs (#210059) next »