Edit report at http://bugs.php.net/bug.php?id=52868&edit=1

 ID:                 52868
 Updated by:         markskilb...@php.net
 Reported by:        sht dot alien at gmx dot net
 Summary:            string variable array acces with string index should
                     emit E_NOTICE
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            Variables related
 Operating System:   Ubuntu Linux 10.04 x64
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

I don't see that this makes sense.



PHP expects an integer for the key, and PHP being PHP, it will just
juggle the type if it can. The PHP Way(tm).


Previous Comments:
------------------------------------------------------------------------
[2010-09-17 11:56:20] sht dot alien at gmx dot net

Description:
------------
It sometimes happens that you accidentially acces a string via array
access and be so unfortunate to have used a string index :-)

Since I see no point in using stingindexes for accessing strings via
array access at any time, I propose to issue an E_NOTICE when a string
index is cast to integer for array access (on strings), if that is
possible.

Test script:
---------------
<?php

$stringValue = 'foobar';



echo $stringValue['baz']; // echoes 'f' since 'baz' is cast to int 0

echo $stringValue['3baz']; // echoes 'b' since the first character of
the index string is 3, thus the index string is cast to int 3

echo $stringValue['ba3z']; // echoes 'f' since 'ba3z' is cast to int 0

?>

Expected result:
----------------
f

b

f



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52868&edit=1

Reply via email to