#33622 [NEW]: $i++ is not $i+1
| From: | meh at v-cm dot net | Date: | Sat, 09 Jul 2005 12:36:23 +0000 |
| Subject: | #33622 [NEW]: $i++ is not $i+1 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-81612@lists.php.net to get a copy of this message | ||
From: meh at v-cm dot net
Operating system: Windows XP
PHP version: 4.3.11
PHP Bug Type: Scripting Engine problem
Bug description: $i++ is not $i+1
Description:
------------
The operators ++ and -- don't increment/decrement boolean values.
This behaviour could be extremly annoying when you have something like:
$key = array_search($thekey, array_keys($thearray));
for($i=$key; $x<count($thearray); $i++)
echo "foo";
Workaround:
$key = array_search($thekey, array_keys($thearray));
if($key==false) $key=0;
for($i=$key; $x<count($thearray); $i++)
echo "foo";
If this behaviour is intended, then it should at least be documented that
++,-- doens't convert boolean values.
Reproduce code:
---------------
// Works
$x = false;
echo $x+1; // Outputs 1
// Doesn't work
$x= false;
$x++;
echo $x; // Outputs nothing
Expected result:
----------------
11
Actual result:
--------------
1
--
Edit bug report at http://bugs.php.net/?id=33622&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33622&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33622&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33622&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33622&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33622&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33622&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33622&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33622&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33622&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33622&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33622&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33622&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33622&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33622&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33622&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33622&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33622&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33622&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33622&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33622&r=mysqlcfg