wepnop Posted May 19, 2011 Share Posted May 19, 2011 Actually i have a very large object thats persistent using sessions. That object have two large arrays, and other things. I have to extract each time that arrays. Now im using: $configuracion = $_SESSION['reg']->GetInvConfig(); $categorias = $_SESSION['reg']->GetInvCategorias(); But if i get it well, this is copying all the array each time, no? i can use a reference to that array in the object easily to improve performace? Quote Link to comment https://forums.phpfreaks.com/topic/236846-using-php-references/ Share on other sites More sharing options...
Adam Posted May 19, 2011 Share Posted May 19, 2011 That's correct. You would need to add an ampersand at the assignment and within the function declaration, to return and assign by reference: [...] public function &GetInvConfig() { [...] $configuracion = &$_SESSION['reg']->GetInvConfig(); Although the arrays would have to be large to make much of a difference to the memory usage. Also just be aware that any changes you make to the array would be reflected within the object. Quote Link to comment https://forums.phpfreaks.com/topic/236846-using-php-references/#findComment-1217450 Share on other sites More sharing options...
wepnop Posted May 19, 2011 Author Share Posted May 19, 2011 That's correct. You would need to add an ampersand at the assignment and within the function declaration, to return and assign by reference: [...] public function &GetInvConfig() { [...] $configuracion = &$_SESSION['reg']->GetInvConfig(); Although the arrays would have to be large to make much of a difference to the memory usage. Also just be aware that any changes you make to the array would be reflected within the object. They can be large, anyway changue it is 1m and 0 if i know it on now. Quote Link to comment https://forums.phpfreaks.com/topic/236846-using-php-references/#findComment-1217467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.