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
 [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: Thu Apr 25 22:01:29 2024 UTC