I have an object that is stored in MySql using serialize()
.
Now I have updated the class definition by making it implement the Serializable
interface, and I can't unserialize object because:
Erroneous data format for unserializing 'ClassName'
Debugging method unserialize()
of this class does not help - it's not even called.
Just as an example, let's say I've got old (A) and new (B) declaration of class:
<?php
class A {
public $hello = "world";
}
class B implements Serializable {
public $hello = "world";
public function serialize() {}
public function unserialize($serialized) { throw new Exception("test"); }
}
now when I try to deserialize data:
$data1 = 'O:1:"A":1:{s:5:"hello";s:5:"world";}';
$data2 = 'O:1:"B":1:{s:5:"hello";s:5:"world";}';
var_dump(unserialize($data1));
var_dump(unserialize($data2));
I get
object(A)#2 (1) {
["hello"]=>
string(5) "world"
}
<br />
<b>Warning</b>: Erroneous data format for unserializing 'B' in <b>[...][...]</b> on line <b>20</b><br />
<br />
<b>Notice</b>: unserialize(): Error at offset 11 of 36 bytes in <b>[...][...]</b> on line <b>20</b><br />
bool(false)