php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5640 When a common name for an array and scalar is used, assignments override each o
Submitted: 2000-07-17 09:41 UTC Modified: 2000-07-17 09:58 UTC
From: alex at zend dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.1pl2 OS: all
Private report: No CVE-ID: None
 [2000-07-17 09:41 UTC] alex at zend dot com
<?php
        $a[0] = "hello";
        $a = "world";
        
        print($a[0] . "\n");
        print($a . "\n");
?>

The following code misbehaves as well:

<?php
        $a = "world";
        $a[0] = "hello";
        
        print($a . "\n");
        print($a[0] . "\n");
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-17 09:49 UTC] rasmus at cvs dot php dot net
This is more of a design decision than a bug.  There are plans to address it in the future though.  When you do $a="world" then $a[0] is the first character of $a or 'w'.  Setting the first character of a string to "hello" makes no sense, so PHP just sets it to "h" and the output should be "horld" and "h".
In the other case I would expect the output to be "world" and "w" since setting $a will overwrite $a[0].
 [2000-07-17 09:49 UTC] stas at cvs dot php dot net
Yes they do. No, this is not a bug. PHP is not Perl.
 [2000-07-17 09:58 UTC] rasmus at cvs dot php dot net
Hey, stop re-opening bug reports.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 08:01:32 2024 UTC