Req #52868 [NEW]: string variable array acces with string index should emit E_NOTICE
| From: | sht dot alien at gmx dot net | Date: | Fri, 17 Sep 2010 09:56:20 +0000 |
| Subject: | Req #52868 [NEW]: string variable array acces with string index should emit E_NOTICE | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-154454@lists.php.net to get a copy of this message | ||
From:
Operating system: Ubuntu Linux 10.04 x64
PHP version: 5.3.3
Package: Variables related
Bug Type: Feature/Change Request
Bug description:string variable array acces with string index should emit E_NOTICE
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 bug report at http://bugs.php.net/bug.php?id=52868&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52868&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52868&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52868&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52868&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52868&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52868&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52868&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52868&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52868&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52868&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52868&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52868&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52868&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52868&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52868&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52868&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52868&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52868&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52868&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52868&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52868&r=mysqlcfg