From:             mehran20 at hotmail dot com
Operating system: CentOS / Linux
PHP version:      5.2.6
PHP Bug Type:     Class/Object related
Bug description:  Seializing objects with private properties

Description:
------------
Hi
Before you read the code, I want to say that the code that is given in
this section works fine. The only problem is for the code that is given in
the "Reproduce code".



class A {
        private $a = 1;
}

class B extends A {
        private $b = 2;
}

$v = new B;
print_r(unserialize(serialize($v)));


Output (which is correct):


B Object ( [b:private] => 2 [a:private] => 1 )

Reproduce code:
---------------
class A {
        private $a = 1;
        public function __sleep() {
                $vars = get_object_vars($this);
                return array_keys($vars);
        }
}

class B extends A {
        private $b = 2;
}

$v = new B;
print_r(unserialize(serialize($v)));

Expected result:
----------------
B Object ( [b:private] => 2 [a:private] => 1 )

Or

B Object ( [b:private] => 2 )

I prefer the first one! But both could be correct!!

Actual result:
--------------
Notice: serialize() [function.serialize]: "a" returned as member variable
from __sleep() but does not exist in <__FILE__> on line 14
B Object ( [b:private] => 2 [a:private] => 1 [a] => )

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

Reply via email to