php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44143 .
Submitted: 2008-02-17 18:04 UTC Modified: 2008-02-18 16:19 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: elias at adaptiveinstance dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3CVS-2008-02-17 (snap) OS: Linux ubuntu 2.6.22-14-386
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: elias at adaptiveinstance dot org
New email:
PHP Version: OS:

 

 [2008-02-17 18:04 UTC] elias at adaptiveinstance dot org
Description:
------------
__set_state can't assign to inherited private properties but creates an new dynamic property.

Reproduce code:
---------------
class A {
	private $foo = 'foo';
	public static function __set_state($state) {
		$a = new A();
		$a->foo = 'bar';
		return $a;
	}
}
class B extends A {
	public static function __set_state($state) {
		$b = new B();
		$b->foo = 'bar';
		return $b;
	}
}
$a = A::__set_state(array());
$b = B::__set_state(array());
var_dump($a, $b);

Expected result:
----------------
object(A)#1 (1) {
  ["foo":"A":private]=>
  string(3) "bar"
}
object(B)#2 (2) {
  ["foo":"A":private]=>
  string(3) "bar"
}

Actual result:
--------------
object(A)#1 (1) {
  ["foo":"A":private]=>
  string(3) "bar"
}
object(B)#2 (2) {
  ["foo":"A":private]=>
  string(3) "foo"
  ["foo"]=>
  string(3) "bar"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-17 19:08 UTC] 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

.
 [2008-02-18 16:19 UTC] elias at adaptiveinstance dot org
ok, i see my mistake. explanation for other's who put a foot in it:

this behaviour is intended by the class system. private properties
are scoped to their class you can redefine them (also dynamically) in
any extending class. so it's really a feature and not a bug. :)

maybe a note of this side effect in the var_export documentation could
help others.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC