Bug #52706 [NEW]: __sleep inhertiance

From: Date: Thu, 26 Aug 2010 10:14:13 +0000
Subject: Bug #52706 [NEW]: __sleep inhertiance
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153805@lists.php.net to get a copy of this message
From:             
Operating system: Win7
PHP version:      5.3.3
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:__sleep inhertiance

Description:
------------
i the case of class "B" extends a class "A" wich define the function
__sleep(), instances of class "B" would class A::__sleep. In this case
class serialzing would be very buggy - i tried something like:
Try: let return the __sleep of class "A" all propertys wich are currently
definied
resoulting Problem: private properety of class "B" are null or NAN
Try: define the function __sleep() in class "B" 
resoulting Problem: private properety of class "A" are null or NAN


Test script:
---------------
class A{
	public $A_A = 10;
	protected $A_B = 11;
	private $A_C = 12;
	public function A(){
		
	}
	private function __sleep(){
		echo "sleep of A()";
		if(get_class($this)	!= "A")
		{
			$d = array_keys( get_class_vars(get_class($this)));
			return ($d);
		}
		return array("A_A","A_B","A_C");
	}
	public function __get($v){
		
		return "PR";
	}
}
class B extends A{
	public 		$B_A = 20;
	protected 	$B_B = 21;
	private 	$B_C = 22;
	public function B(){
		$this->A();
	}
	public function __sleep(){ 
		return
array("A_A","A_B","A_C","B_A","B_B","B_C");
	} /* remove this __sleep would let php use A::__sleep()

}
$a = new A();
$b = new B();
echo "<br/>A";
echo "<br/>" .  htmlspecialchars(serialize($a));
echo "<br/>B";
echo "<br/>" .  htmlspecialchars(serialize($b));


Expected result:
----------------
the complettely serialized Object like with out __sleep()!

Actual result:
--------------
private propertys of parent or child are null or NAN with defined __sleep()

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52706&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=52706&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=52706&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=52706&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=52706&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52706&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=52706&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=52706&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=52706&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=52706&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=52706&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=52706&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=52706&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=52706&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=52706&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52706&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52706&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=52706&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=52706&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=52706&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=52706&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=52706&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#153805) next »