note 75755 deleted from language.operators.increment by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:22:37 +0000 |
| Subject: | note 75755 deleted from language.operators.increment by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189855@lists.php.net to get a copy of this message | ||
Note Submitter: rowan dot collins at gmail dot com
----
As the manual says, decrementing NULL in this way yields NULL, although incrementing it yields 1, as
you might expect. Can't quite see why this makes sense, but if you need to work around it, you
can use '-= 1' instead:
<?php
$i = null;
--$i;
var_dump($i); // NULL
$i--;
var_dump($i); // NULL
$i-=1;
var_dump($i); // int(-1)
?>
Note that -= returns the value assigned, so treat it like '--$i', not '$i--' if
you're testing the value.