Re: bool values and increment operators?
| From: | Chase Peeler | Date: | Mon, 25 Mar 2019 15:08:31 +0000 |
| Subject: | Re: bool values and increment operators? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104934@lists.php.net to get a copy of this message | ||
On Mon, Mar 25, 2019 at 11:03 AM Christian Schneider <cschneid@cschneid.com>
wrote:
> 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.
>
> $i = false;
$i+=1;
var_dump($i);
that outputs
int(1)
I'd say that
1.) Update the documentation to add booleans to the second list
2.) Update the documentation to remove the second list - anything not in
the first list is not affected.
3.) Update the language so that ++ and -- cast booleans to ints.
I don't think #3 is actually a good solution.
> - Chris
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Chase Peeler
chasepeeler@gmail.com