|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-07-20 01:54 UTC] nospam0 at malkusch dot de
 Description:
------------
$string = 'a bla'; 
$string['index'] = 'b blub'; 
 
does the same work as 
 
$string = 'a bla'; 
$string{(int)'index'} = 'b blub'{0}; 
 
without any notic of undefined index or too long replacing 
string. But it should throw any notice, because one could 
expect that the code should produce a new Array('index' => 
'b blubb'). 
 
Reproduce code:
---------------
$string = 'a bla';
$string['index'] = 'b blub';
var_dump($string);
Expected result:
----------------
Either notices for use of deprecated [], undefined offset 
'index' and too long replace char (and of course the 
actual result) 
 
or 'a bla' is deleted and $string has array('index' => 'b 
blubb') as value. 
Actual result:
--------------
string(5) "b bla" 
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 11:00:01 2025 UTC | 
> It's expected behaviour: 'index' is casted to it's > integer value (0), that's why you get this result. But as I use $string[] and not $string{} it's undefined wether it should be a new array or a string. So why doesn't PHP throw an error?Why should it? It's only deprecated, not obsolete -- and there's not even a hint of a date being scheduled for its withdrawal. (Deprecated meaning, roughly, not encouraged and may be withdrawn one day, maybe, if the php gurus ever get around to it.) As withdrawal of this feature hasn't been announced yet, I think you can take it it'll probably be around at least for the lifetime of PHP 5 -- but the use of {} instead of [] is strongly encouraged. Cheers! Mike