#42611 [Opn->Bgs]: increment operator (++) on unset overloaded variable not produces 1

From: Date: Tue, 11 Sep 2007 07:09:37 +0000
Subject: #42611 [Opn->Bgs]: increment operator (++) on unset overloaded variable not produces 1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-117377@lists.php.net to get a copy of this message
ID: 42611 User updated by: johnny at netvor dot sk Reported By: johnny at netvor dot sk -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: all PHP Version: 5.2.4 New Comment: PEBCAC Previous Comments: ------------------------------------------------------------------------ [2007-09-11 02:32:53] judas dot iscariote at gmail dot com Please, read your code, this is the expected behaviuor, there is a bug in your code. accessing: private $data; as: $data[$name] will not work for sure ;) $this->data[$name] will ;) ------------------------------------------------------------------------ [2007-09-10 13:36:55] johnny at netvor dot sk Description: ------------ calling unary increment operator (++) on unset overloaded member variable leaves variable unset instead of setting it to 1 Reproduce code: --------------- <?php class A { public $v; } class B { private $data; public function __set ($name, $value) { $data[$name] = $value; } public function __get ($name) { return $data[$name]; } } $a = new A (); $b = new B (); $a->v++; $b->v++; echo "\$a->v is: {$a->v}<br/>"; echo "\$b->v is: {$b->v}<br/>"; ?> Expected result: ---------------- $a->v is: 1 $b->v is: 1 Actual result: -------------- $a->v is: 1 $b->v is: ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42611&edit=1

« previous php.bugs (#117377) next »