#44143 [Bgs]: .

From: Date: Mon, 18 Feb 2008 16:19:00 +0000
Subject: #44143 [Bgs]: .
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122414@lists.php.net to get a copy of this message
 ID:               44143
 User updated by:  elias at adaptiveinstance dot org
-Summary:          __set_state can't assign to inherited private
                   properties
 Reported By:      elias at adaptiveinstance dot org
 Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Linux ubuntu 2.6.22-14-386
 PHP Version:      5.3CVS-2008-02-17 (snap)
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-02-17 19:08:38] 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-17 18:04:39] 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"
}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44143&edit=1


Thread (3 messages)

« previous php.bugs (#122414) next »