JohnFish Posted December 14, 2006 Share Posted December 14, 2006 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 workAlso, is there anything else that important that has changed to this version?thx Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/ Share on other sites More sharing options...
JohnFish Posted December 14, 2006 Author Share Posted December 14, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140783 Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 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 Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140789 Share on other sites More sharing options...
JohnFish Posted December 14, 2006 Author Share Posted December 14, 2006 The problem is that in my local server it workds without using the & operator, while in the production server it copies by reference. Both are using php 5.2 Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140816 Share on other sites More sharing options...
JohnFish Posted December 14, 2006 Author Share Posted December 14, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140818 Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 Hmm,I don't think there is anything in php.ini that would force a variable to be passed by reference.The only thing I can offer is the part of the manual about reference variables:http://us2.php.net/manual/en/language.references.php Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140827 Share on other sites More sharing options...
btherl Posted December 14, 2006 Share Posted December 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-140832 Share on other sites More sharing options...
JohnFish Posted December 14, 2006 Author Share Posted December 14, 2006 register globals is enabled in the production server but i have no control over the php.ini file. is there any way to disable register globals or get the same effect as if it was disabled? Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-141075 Share on other sites More sharing options...
wildteen88 Posted December 14, 2006 Share Posted December 14, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/30576-514-vs-52-string-reference-not-copy/#findComment-141308 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.