php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33622 $i++ is not $i+1
Submitted: 2005-07-09 14:36 UTC Modified: 2005-07-14 11:26 UTC
From: meh at v-cm dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.11 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: meh at v-cm dot net
New email:
PHP Version: OS:

 

 [2005-07-09 14:36 UTC] meh at v-cm dot net
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-09 14:43 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2005-07-09 14:44 UTC] derick@php.net
Right, but afaik it's not documented, so making it a doc problem.
 [2005-07-09 17:59 UTC] sean@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

added note: "The increment/decrement operators do not affect boolean values." to language.operators.increment
 [2005-07-10 00:11 UTC] johannes@php.net
it should also mention NULL: 
 
NULL++ -> 1 
NULL-- -> NULL 
 
and maybe even arrays and objects should be mentioned - 
they don't change. 
 [2005-07-14 11:26 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Decrementing NULL values has no effect too, but incrementing them results in 1."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 12:01:32 2024 UTC