bool values and increment operators?
| From: | Dan Ackroyd | Date: | Mon, 25 Mar 2019 14:43:34 +0000 |
| Subject: | bool values and increment operators? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-104932@lists.php.net to get a copy of this message | ||
Hi internals,
So this code:
<?php
declare(strict_types=1);
$i = true;
$i++;
var_dump($i);
$i--;
var_dump($i);
$i = false;
$i++;
var_dump($i);
$i--;
var_dump($i);
outputs:
bool(true)
bool(true)
bool(false)
bool(false)
which is quite surprising on multiple levels.
Does anyone know if this behaviour is deliberate, or is it just an
oversight that could have an RFC applied to it?
cheers
Dan
Ack
btw I realised that the behaviour is like it is, from someone asking
for help debugging this code:
<?php
$i=0;
$j=2;
$exit = 0;
while(10-$i++||$i=0||--$j){
echo$i.' - '.$j."\n";
if($exit++ == 30) exit();
}