I would like to use a static variable inside a method in an object to
hold a reference to another object. But i can't get it to work. Here
is an example
class B{
var $test;
}
class A{
function hold($a){
static $ref;
if(is_object($a )){
$ref = $a;
}
print $ref->test;
}
}
$a = new A;
$b = new B;
$b->test = 10;
$a->hold($b);
$b->test = 11;
$a->hold();
output
------
10
10
Should be
---------
10
11
If i try passing it in as a refrence the second call gives nothing as
if it forgot about it.
class A{
function hold(&$a){
static $ref = 0;
if(is_object($a )){
$ref = &$a;
}
print $ref->test;
}
}
output
------
10
0
Can someone help me here
Thanks
hold a reference to another object. But i can't get it to work. Here
is an example
class B{
var $test;
}
class A{
function hold($a){
static $ref;
if(is_object($a )){
$ref = $a;
}
print $ref->test;
}
}
$a = new A;
$b = new B;
$b->test = 10;
$a->hold($b);
$b->test = 11;
$a->hold();
output
------
10
10
Should be
---------
10
11
If i try passing it in as a refrence the second call gives nothing as
if it forgot about it.
class A{
function hold(&$a){
static $ref = 0;
if(is_object($a )){
$ref = &$a;
}
print $ref->test;
}
}
output
------
10
0
Can someone help me here
Thanks
Comment