PDA

View Full Version : Param By Reference


juancho_h
04-01-2010, 06:05 AM
Hi, I have a little problem.
I'm re-writing some functions from PHP to Java, and i need to use params by reference. There is any chance to do that?

Thanks..

nam
04-01-2010, 04:41 PM
You can pass a reference to any Java function by annotating the argument with @Reference

com.caucho.quercus.annotations.Reference

sblommers
06-01-2010, 09:35 AM
$var=array('a'=>array(1,2,3),'b'=>array(4,5,6));

foreach ($var as &$sub) {
foreach ($sub as &$element) {
$element=$element+1;
}
}

var_dump($var);


OUTPUT APACHE+PHP
array(2) {
["a"]=>
array(3) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(4)
}
["b"]=>
&array(3) {
[0]=>
int(5)
[1]=>
int(6)
[2]=>
&int(7)
}
}

OUTPUT QUERCUS
array(2) {
["a"]=>
&array(3) {
[0]=>
&int(2)
[1]=>
&int(3)
[2]=>
&int(4)
}
["b"]=>
&array(3) {
[0]=>
&int(5)
[1]=>
&int(6)
[2]=>
&int(7)
}
}

Doesn't this have any side-effects when looping another nest?

Sebastiaan

juancho_h
06-19-2010, 05:17 AM
You can pass a reference to any Java function by annotating the argument with @Reference

com.caucho.quercus.annotations.Reference
Sorry I totally forgot about this post. Thanks for your help it works just perfect!
The only thing is that if I pass a literal value instead of a var it should throw an error, but there is not error.

juancho_h
06-19-2010, 05:20 AM
You can pass a reference to any Java function by annotating the argument with @Reference

com.caucho.quercus.annotations.Reference
Sorry I totally forgot about this post. Thanks for your help it works just perfect!
The only thing is that if I pass a literal value instead of a var it should throw an error, but there is not error.