php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24494 incorrect value for texte in array
Submitted: 2003-07-04 08:08 UTC Modified: 2003-07-04 10:14 UTC
From: bibifoc23 at yahoo dot fr Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.2 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bibifoc23 at yahoo dot fr
New email:
PHP Version: OS:

 

 [2003-07-04 08:08 UTC] bibifoc23 at yahoo dot fr
Description:
------------
hello,

I get strange behaviour with array:

<?php

$array = array ( 'TM' => 'test', 'autre dossier' => 'texte' ) ;

print_r ( $array );

echo $array['TM']['TM']."\n";
?>

the echo command return the first character of string. But $array['TM'] is not an array, so i expext to have an error wen i call $array['TM']['TM']. 
But PHP convert the second index to 0. 

Thanks

Reproduce code:
---------------
<?php

$array = array ( 'TM' => 'test', 'autre dossier' => 'texte' ) ;

print_r ( $array );

echo $array['TM']['TM']."\n";
?>


Expected result:
----------------
return error or warning.

Actual result:
--------------
return the first character of the string

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-04 10:14 UTC] jay@php.net
This is expected behaviour, I believe. $array['TM'] is not 
an array, it's a string, but strings can be treated like 
arrays. So 'TM' gets converted to 0 given PHP's type 
juggling rules, and $array['TM'][0] is 't', so it's 
working as expected. 
 
J 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 00:01:30 2024 UTC