UPDATE: As someone says this question is a bit unclear. I couldn't really understand it myself. But I did dig up the solution. It's a PHP bug that has been resolved. The server this legacy code runs on has an outdated php version.
Old code:
class MyChildClass extends MyBaseClass
{
protected $myProp = "foo";
}
class MyBaseClass {
}
$myObject = new MyChildClass();
$myObjectS = serialize($myObject);
New code:
class MyChildClass extends MyBaseClass
{
}
class MyBaseClass {
public $myProp;
}
// $myObjectS is the same as in the Old code above.
$myObject = unserialize($myObjectS);
This will result in an object with a protected property $myProp with a value of "foo". But there will also be a public property with the same name with an undefined value.
I really do not know how to fix this. The result I want is to have the objects public property populated with the serialized objects value for its protected property.
I would not design the code like this with the serialization of complete objects. But this is a legacy project where I (for the time being) have to deal with this.
$myObjectS
in "New code" coming from? It must be from "Old code", but that's another file. Or not? What? Why call it "Old" and "New" in the first place, that must have a meaning... normally you would say that when you replace code, but I don't think that's the case here... or is it?