This is to show the affect of changing property of object A through another object B when you pass object A as a property of another object B.
<?php
class A{
public $info;
function __construct(){
$this->info = "eeee";
}
}
class B_class{
public $A_obj;
function __construct($A_obj){
$this->A_obj = $A_obj;
}
public function change($newVal){
$this->A_obj->info = $newVal;
}
}
$A_obj = new A();
echo 'A_obj info: ' . $A_obj->info . '<br/>';
$B_obj = new B_class($A_obj);
echo 'B_obj info: ' . $B_obj->A_obj->info . '<br/>';
$B_obj->change('xxxxx');
echo 'B_obj info after change: ' . $B_obj->A_obj->info . '<br/>';
echo 'A_obj info: ' . $A_obj->info . '<br/>';
?>
The result:
A_obj info: eeee
B_obj info: eeee
B_obj info after change: xxxxx
A_obj info: xxxxx