#20644 [Opn]: Incrementing/Decrementing booleans != boolean+1

From: Date: Sat, 25 Jan 2003 19:28:40 +0000
Subject: #20644 [Opn]: Incrementing/Decrementing booleans != boolean+1
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969351301@lists.php.net to get a copy of this message
ID: 20644 Updated by: hholzgra@php.net Reported By: yury@krasu.ru Status: Open Bug Type: Documentation problem Operating System: all PHP Version: 4.3.0-dev New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2002-11-27 04:24:49] 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) ------------------------------------------------------------------------ [2002-11-27 02:56:32] 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 01:49:34] sniper@php.net Reclassified. ------------------------------------------------------------------------ [2002-11-27 01:24:49] yury@krasu.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-26 20:37:54] sniper@php.net Not known and most likely user error. Please provide a reproducing script. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/20644 -- Edit this bug report at http://bugs.php.net/?id=20644&edit=1

« previous php.doc (#969351301) next »