parent::__destruct() inside child's __construct() doesn't deallocate a
parent class member-variable in php
the member variables of a parent class is not deallocated from the child
class object if the child class construtor calls the parents destructor.
<?php
class c1
{
public $a=10;
public function __construct()
{
echo "Called Construct_c1()<br>";
}
}
class c2 extends c1
{
public $b=20;
public function __construct()
{
parent::__destruct();//Fatal error: Call to undefined method
c1::__destruct()
echo "Called Construct_c2()<br>";
}
public function __destruct()
{
echo "Called Destruct_c2()<br>";
}
}
$obj1_c2 = new c2();
unset($obj1_c2);
?>
No comments:
Post a Comment