php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43395 unserialize reinitialize unsetted object's properties
Submitted: 2007-11-24 11:58 UTC Modified: 2007-11-24 12:11 UTC
From: ramdac at sweetorange dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: Linux 2.6.20-16-generic
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ramdac at sweetorange dot it
New email:
PHP Version: OS:

 

 [2007-11-24 11:58 UTC] ramdac at sweetorange dot it
Description:
------------
If I unset an object property, after serialize/unserialize the property is re-initialized with default value defined in class declaration.

Reproduce code:
---------------
class test
{
    public $testUnset = 'default value';
}

$o = new test();
var_dump($o);

unset($o->testUnset);
var_dump($o);

$s = serialize($o);
$oo = unserialize($s);
var_dump($oo);

Expected result:
----------------
object(test)#1 (1) {
  ["testUnset"]=>
  string(13) "default value"
}
object(test)#1 (0) {
}
object(test)#2 (1) {
}

Actual result:
--------------
object(test)#1 (1) {
  ["testUnset"]=>
  string(13) "default value"
}
object(test)#1 (0) {
}
object(test)#2 (1) {
  ["testUnset"]=>
  string(13) "default value"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-24 12:11 UTC] jani@php.net
Of course it is set, unserialize() process uses the class definition for re-creating the object. And as your class has the default value, of course it will be re-created.

See also:
http://fi2.php.net/manual/en/language.oop.serialization.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 17 10:00:03 2025 UTC