Jump to content

5.1.4 vs 5.2 (string reference not copy)


JohnFish

Recommended Posts

Hi guys. The admin of the server wher my php website is hosted changed from php 5.1.x to 5.2. I noticed that strings are now copied by reference and not by value.

How can I get the same effect from a string? clone doesnt work

Also, is there anything else that important that has changed to this version?

thx
Link to comment
Share on other sites

I have upgraded my devserver php version to 5.2 but I dont get this problem.

I am doing

//create query
$_SESSION['query'] = $query; //then store it to session
//then do more stuff to query.

Shouldn't the $_SESSION['query'] = $query; be done via copy by value? thx
Link to comment
Share on other sites

if you set your session var equal to $query, then do further operations on the $query variable, they will not automatically be applied to the session var...meaning, the session var is a copy of the $query var at the time of the " = " operation.

You can create a reference to the $query var using the "&=" operator.

[code]$_SESSION['query'] &= $query;[/code]
Link to comment
Share on other sites

[quote author=hitman6003 link=topic=118539.msg484460#msg484460 date=1166059208]
if you set your session var equal to $query, then do further operations on the $query variable, they will not automatically be applied to the session var...meaning, the session var is a copy of the $query var at the time of the " = " operation.

You can create a reference to the $query var using the "&=" operator.

[code]$_SESSION['query'] &= $query;[/code]
[/quote]

Actually I just read your answer. The thing is that in my server, further operations on $query ARE automatically applied to session var. thats the problem.
Link to comment
Share on other sites

Can you post exact code that reproduces the behaviour?  A copy of the php.ini on both servers would help too.  There's been no "auto-copy-by-reference" change in 5.2, so the source of the unexpected behaviour is somewhere else.

Edit: It may well be this:

[quote]If register_globals  is enabled, then each global variable can be registered as session variable. Upon a restart of a session, these variables will be restored to corresponding global variables. Since PHP must know which global variables are registered as session variables, users need to register variables with session_register() function. You can avoid this by simply setting entries in $_SESSION.

If register_globals  is enabled, then the global variables and the $_SESSION entries will automatically reference the same values which were registered in the prior session instance. However, if the variable is registered by $_SESSION  then the global variable is available since the next request.[/quote]
Link to comment
Share on other sites

If you can use .htaccess files then you may be able to disable register_globals by adding the following to a .htaccess file:

[code]php_flag register_globals Off[/code]

Preferably add it/create a .htaccess file in the document root (the folder you upload your files to). That way it will be disabled throughout your website. Note you will know if its disabled by looking at the local Value column when running phpinfo.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.