Why does the serialization?

Why the public_key property is not serilized?
I have serenitatis class B which extends class A
But the property public_key why it does not want sheralizoda, why does he have this behavior?
class A{
 private $public_key = ";

 protected function __construct($public_key)
{
 $this->public_key = $public_key;
}
 public function __sleep()
{
 return array('public_key');
}
}

class B extends A{
 public function __construct($public_key = 'hello')
{
parent::__construct($public_key);
}
}

$b = new B();
var_dump($b);
var_dump(unserialize(serialize($b)));


object(B)#1 (1) {
["public_key":"A":private]=>
string(5) "hello"
}
PHP Notice: serialize(): "public_key" returned as member variable from __sleep() but does not exist in /home/master/test.php on line 24
object(B)#2 (2) {
["public_key":"A":private]=>
string(0) ""
["public_key"]=>
NULL
}
March 23rd 20 at 19:46
1 answer
March 23rd 20 at 19:48
Solution
Because you public_key private. Private properties and methods are not inherited, replace it with a protected

Find more questions by tags PHP