I was wondering if there was a way to return a reference of an object
that lies within another object...
<?php
class my_class_1{
var $_db=NULL;
function my_class_1(){
$this->_db=new my_class_2(TRUE );
return TRUE;
}
function get_db(&$db){
$db=&$this->db;
return TRUE;
}
}
class my_class_2{
var $var1=NULL;
function my_class_2($var ){
$this->var1=$var;
return TRUE;
}
}
$object=new my_class_1();
$object->get_db($db);
var_dump($db);
?>
This gives:
NULL
I was hoping for:
object(my_class _2)(1) {
["var1"]=>
bool(true)
}
Anyone know of a way to do this, or can you only return a copy instead
of the reference?
that lies within another object...
<?php
class my_class_1{
var $_db=NULL;
function my_class_1(){
$this->_db=new my_class_2(TRUE );
return TRUE;
}
function get_db(&$db){
$db=&$this->db;
return TRUE;
}
}
class my_class_2{
var $var1=NULL;
function my_class_2($var ){
$this->var1=$var;
return TRUE;
}
}
$object=new my_class_1();
$object->get_db($db);
var_dump($db);
?>
This gives:
NULL
I was hoping for:
object(my_class _2)(1) {
["var1"]=>
bool(true)
}
Anyone know of a way to do this, or can you only return a copy instead
of the reference?
Comment