On Mon, Mar 25, 2019 at 11:03 AM Christian Schneider <cschn...@cschneid.com>
wrote:

> Am 25.03.2019 um 15:43 schrieb Dan Ackroyd <dan...@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
chasepee...@gmail.com

Reply via email to