Edit report at http://bugs.php.net/bug.php?id=51412&edit=1
ID: 51412 Updated by: johan...@php.net Reported by: looris at gmail dot com Summary: inconsistency using uninitialized array elements -Status: Open +Status: Bogus Type: Bug Package: Arrays related Operating System: linux, osx, (any?) PHP Version: Irrelevant New Comment: The documentation claims The increment/decrement operators do not affect boolean values. Decrementing NULL values has no effect too, but incrementing them results in 1. http://php.net/manual/en/language.operators.increment.php This might be considered inconsistent but changing this would be a rather random compatibility break. Previous Comments: ------------------------------------------------------------------------ [2010-03-27 15:00:22] looris at gmail dot com Description: ------------ While I agree that it would be better to actually initialize elements before using them, it is anyway wrong that they behave in inconsistent ways when you do that. They should BOTH count as 0, hence become 1 and -1, OR they should **BOTH** stay NULL. It does not make any sense at all to have them behave in two different ways. Test script: --------------- $pitale=array(); $pitale["ok"]++; $pitale["bug"]--; print_r($pitale); Expected result: ---------------- Array ( [ok] => 1 [bug] => -1 ) ---OR--- Array ( [ok] => [bug] => ) Actual result: -------------- Array ( [ok] => 1 [bug] => ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51412&edit=1