This is my class
abstract class DataStore_Adapter {
private $id;
abstract function update();
abstract function insert();
function __construct() {
$this-> id = 3;
}
function save() {
if(! is_null($this->id)) {
$this->update();
} else {
$this->insert();
}
}
}
class VS_DataStroe_Adapter extends DataStore_Adapter {
function __construct() {
parent:: save();
}
function update() {
echo "successfully updated!";
}
function insert() {
echo "successfully inserted!";
}
}
$vs_data = new VS_DataStroe_Adapter();
Running this code i get the result
successfully inserted!
and if i remove
$this-> id = 3;
from the constructor method of DataStore_Adapter and place it inside function save() it gives me result;
successfully updated!
I need a clarification on this behavior. As i have declared $id as a private variable , i know its only can be access through DataStore_Adapter class. But when i initialize it inside save() method sub-class can access its value.. How this is possible? and why?