Jump to content

Using php references


wepnop

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/236846-using-php-references/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.