This will work if you set the property by reference.
public function __construct(&$db_conn){
$this->db_conn = &$db_conn; // note the &
var_dump($this->db_conn);
}
To make this abundantly clear, here 2 testcases:
class reftest {
public $test = NULL;
public function __construct(&$test) {
$this->test = &$test;
}
}
$test = 'a';
echo "\$test before: $test<br>";
$reftest = new reftest($test);
echo "\$test after: $test and " . $reftest->test . "<br>";
$test = 'b';
echo "\$test after: $test and " . $reftest->test . "<br>";
output:
$test before: a
$test after: a and a
$test after: b and b
if you miss one of the &
symbols you get the behavior you describe:
class reftest {
public $test = NULL;
public function __construct(&$test) {
$this->test = $test;
}
}
$test = 'a';
echo "\$test before: $test<br>";
$reftest = new reftest($test);
echo "\$test after: $test and " . $reftest->test . "<br>";
$test = 'b';
echo "\$test after: $test and " . $reftest->test . "<br>";
output:
$test before: a
$test after: a and a
$test after: b and a