Re: bool values and increment operators?
| From: | Christian Schneider | Date: | Mon, 25 Mar 2019 15:03:37 +0000 |
| Subject: | Re: bool values and increment operators? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104933@lists.php.net to get a copy of this message | ||
Am 25.03.2019 um 15:43 schrieb Dan Ackroyd <danack@basereality.com>:
> 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.
The documentation has a highlighted box stating
"Note: The increment/decrement operators only affect numbers and strings. Arrays, objects and
resources are not affected. Decrementing NULL values has no effect too, but incrementing them
results in 1."
I guess bools should be added to the list of things not affected.
- Chris