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

 ID:                 52706
 Updated by:         johan...@php.net
 Reported by:        dev dot php at linke-t dot net
 Summary:            __sleep inhertiance
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Win7
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

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

Yes, class design has to be well thought.


Previous Comments:
------------------------------------------------------------------------
[2010-08-26 12:14:10] dev dot php at linke-t dot net

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 this bug report at http://bugs.php.net/bug.php?id=52706&edit=1

Reply via email to