php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20644 Incrementing/Decrementing booleans != boolean+1
Submitted: 2002-11-26 07:32 UTC Modified: 2004-07-27 14:42 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: yury at krasu dot ru Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.0-dev OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: yury at krasu dot ru
New email:
PHP Version: OS:

 

 [2002-11-26 07:32 UTC] yury at krasu dot ru
After installing PHP 4.2.1 in some time I noticed a strange bug:
at some situation increment operation (++) didn't work!
I failed to write a simple code to reproduce that bug (it occurs regular at the same situation in nested functions of a rather big project), but in short - 
when trying to increment by ++ operation a function parameter, which was setted to 1 as a default parameter value of upper function (which called that function), incrementation does NOT happen.
and such code as

echo $newteamid;
$newteamid++;
echo $newteamid;
$a = $newteamid;
echo $a;
$a++;
echo $a;

produces an output: "1111"
but if I use " += 1" instead of "++" all works ok (and I was to make so at my project)

as I mentioned I tried to reproduce that bug at simple code, but it works ok in a short program with the same variables values.  
and the same occurs at PHP 4.2.3.

if that bug is not known I can try to write an example for this (dont wanna waste a time if it's well-known) but please confirm that

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-26 20:37 UTC] sniper@php.net
Not known and most likely user error. Please provide a reproducing script.

 [2002-11-27 01:24 UTC] yury at krasu dot ru
it was really an user error, sorry.
i found than "++" operator doesn't make type conversion from boolean to int, and if variable is boolean and equals TRUE than after ++ it remains as TRUE, so

$a = TRUE; echo ($a++).$a;

produces output "11"
this behavior of increment operator was unexpected to me and i suppose that it can be the same to others, so i wrote an user note at "type juggling" part at online documentation
 [2002-11-27 01:49 UTC] sniper@php.net
Reclassified.

 [2002-11-27 02:56 UTC] philip@php.net
Please explain how this is to be documented (why this isn't a bug) as I fail to understand the seemingly inconsistent behavior of this example:

$t = true;
$a = $t + 1; (same as $t += 1; // 2)
$b = ++$t;

print "a: $a b: $b"; // a: 2 b: 1

In otherwords, incrementing/decrementing a boolean keeps it as boolean while adding an integer, such as 1, changes it to an integer.

Reclassifying as a scripting engine problem so php-dev gets this report.  Please provide a documentable reason for this behavior.
 [2002-11-27 04:24 UTC] sniper@php.net
it's still not a bug, and there was some discussion about this on php-dev or some other list a while ago..can't find that now thouhg, but there was also "fix" for this, but it was reverted. (iirc)

 [2003-01-25 13:28 UTC] hholzgra@php.net
compare this to

$a = "a";
$a = $a + 1;

and 

$a = "a";
$a = $a++;

++ is defined as increment, which may have different meanings on different types

it is *not* defined as "is always the same as +=1 "

so it is definetly not a bug IHMO

the documentation issue is still valid 
 [2004-07-27 14:42 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.

"Incrementing or decrementing booleans has no effect."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC