From:             claudio dot frizziero at nereal dot com
Operating system: Fedora Core 4
PHP version:      5.0.5
PHP Bug Type:     Feature/Change Request
Bug description:  Behaviour of array brackets with strings

Description:
------------
Array brackets can be used, for backwards compatibility, to specify a
zero-based offset of a char on a string. However, current implementation
is ambiguous and forces to use dirty workaround to avoid the problem - if
you realize that it doesn't work as you imagine.


The ambiguity resides on the different behaviour of the same syntax using
different types of keys and values:
- $string[$int] works like $string{$int}
- $int[$int] gives NULL
- $string[$string] works like $string{0}
- $int[$string] gives NULL

My request is:
- add a directive into the configuration file to disable the
"compatibility mode" of array brackets (just because it's deprecated: I
can test my script before it will definitively changed)

or - alternately, as a temporary workaround:

- if the type of key is string, parser assumes that is a key, not an
offset


Thank you for taking the time to read me. =)

Reproduce code:
---------------
$t = 'abc';
var_dump ($t[1]);
var_dump ($t['key']);
$t = 123;
var_dump ($t[1]);
var_dump ($t['key']);

Expected result:
----------------
NULL NULL NULL NULL

Actual result:
--------------
string(1) "b" string(1) "a" NULL NULL

-- 
Edit bug report at http://bugs.php.net/?id=34848&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34848&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34848&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34848&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34848&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34848&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34848&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34848&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34848&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34848&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34848&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34848&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34848&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34848&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34848&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34848&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34848&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34848&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34848&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34848&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34848&r=mysqlcfg

Reply via email to