I've got two scripts and their outputs:
1st script
class A {
public $view = "foo";
public function getView()
{
return $this->view;
}
}
$a = new A();
$b = serialize($a);
file_put_contents("/tmp/test.tmp",$b);
var_dump($b);
and it's output:
object(A)[1]
public 'view' => string 'foo' (length=3)
string 'O:1:"A":1:{s:4:"view";s:3:"foo";}' (length=33)
than I run:
2nd script
class A {
private $view = "bar";
public function getView()
{
return $this->view;
}
}
$a = unserialize(file_get_contents("/tmp/test.tmp"));
var_dump($a, $a->getView());
and it displays:
object(A)[1]
private 'view' => string 'bar' (length=3)
public 'view' => string 'foo' (length=3)
string 'bar' (length=3)
As you can see the only change is that public $view became private.
My coleague Peter found this, mind blown :)
Edit:
I believe it could be really problematic if you serialize some objects (thru Doctrine for example) to DB, than update your codebase without updating data stored in DB (which will became - as I assume - parsing objects serialized to text and update them with some migration scripts) and then unserialize data and work on it. It's not so uncommon I think and behaviour of that could be uncontrolled. Would love to see PHP throwing an error/exception etc. if unserialized object class definition differs from actual one.