#20548 [Com]: Decrement ("$x[$y]--") doesn't work on uninitiated variable
ID: 20548
Comment by: lew at mailduct dot com
Reported By: prgallier at yahoo dot com
Status: Wont fix
Bug Type: Scripting Engine problem
Operating System: Linux 2.4
PHP Version: 4.3.2-dev
New Comment:
This is a GROSS inconsistency in how the increment/decrement operators
work, and one that coders are likely to stumble upon the hard way.
Please study the effect of fixing this, at the expense of breaking a
long-time quirk in BC. Breaking a quirk, and documenting it on the BC
page, is better than maintaining a GROSS inconsistency in one of the
basic language construct operators! Please fix this!
Previous Comments:
------------------------------------------------------------------------
[2003-08-03 12:57:49] iliaa@php.net
This is a valid bug, however a fix would be a BC break that would
result in a beahviour change that was in place since 3.0 days.
------------------------------------------------------------------------
[2003-02-14 17:14:59] bulletbait at yahoo dot com
I just stumbled across this bug recently with an older version (4.1.1)
of PHP on Win32 -- verified that it still exists in 4.3.0. This one
had me going in circles trying to debug. Work-arounds:
$score[$num] -= 1;
or
$score[$num] = $score[$num] - 1;
------------------------------------------------------------------------
[2002-11-21 12:42:11] prgallier at yahoo dot com
The following:
$score[$num]--;
does not affect $score[$num] if $score[$num] is uninitiated.
Using $score[$num]++ does work, however.
This is inconsistent.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20548&edit=1
Thread (9 messages)