#41690 [Bgs]: Decrementing null is null
| From: | ian at ithomas dot name | Date: | Thu, 14 Jun 2007 15:46:55 +0000 |
| Subject: | #41690 [Bgs]: Decrementing null is null | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113792@lists.php.net to get a copy of this message | ||
ID: 41690
User updated by: ian at ithomas dot name
Reported By: ian at ithomas dot name
Status: Bogus
Bug Type: Math related
Operating System: Gentoo
PHP Version: 5.2.3
New Comment:
Thanks for your response. Since filing this I've found
http://uk2.php.net/manual/en/language.operators.increment.php
which
states:
"Decrementing NULL values has no effect too, but incrementing them
results in 1."
but with no further explanation. I assume it is because this behaviour
is documented that you are saying that this is not a bug.
This behaviour is counter-intuitive, so unless there is a good reason
for it (which should be mentioned in the documentation) it remains a
bug. Documenting a bug doesn't fix it!
Previous Comments:
------------------------------------------------------------------------
[2007-06-14 15:39:36] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
.
------------------------------------------------------------------------
[2007-06-14 14:31:02] ian at ithomas dot name
Description:
------------
Incrementing null is 1.
Decrementing null is null!
I'm not sure which is the correct behaviour, but they should at least
be consistent.
I saw this on PHP 4.4.4 but have since duplicated it on 5.2.3. It was a
problem for me because I had a "for ($i = null; $i > 0; $i--)" which
results in an infinite loop (but would work fine if $i++ was used
instead).
Reproduce code:
---------------
<?php
echo '$i++: ';
$i = null;
var_dump($i);
$i++;
var_dump($i);
echo '<br> <br> <br> $i--: ';
$i = null;
var_dump($i);
$i--;
var_dump($i);
echo '<br> <br> <br> $i - 1: ';
$i = null;
var_dump($i);
$i = $i - 1;
var_dump($i);
?>
Expected result:
----------------
null-- should be 1, so script should output:
$i++: NULL int(1)
$i--: NULL int(-1)
$i - 1: NULL int(-1)
Actual result:
--------------
null-- is null, script output is:
$i++: NULL int(1)
$i--: NULL NULL
$i - 1: NULL int(-1)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41690&edit=1