php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42611 increment operator (++) on unset overloaded variable not produces 1
Submitted: 2007-09-10 13:36 UTC Modified: 2007-09-11 07:09 UTC
From: johnny at netvor dot sk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.4 OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: johnny at netvor dot sk
New email:
PHP Version: OS:

 

 [2007-09-10 13:36 UTC] 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: 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-11 02:32 UTC] 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-11 07:09 UTC] johnny at netvor dot sk
PEBCAC
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 03:01:31 2025 UTC