Copy an object into another object as value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kcravimss
Forum Newbie
Posts: 2
Joined: Thu Feb 07, 2008 12:40 pm

Copy an object into another object as value

Post by kcravimss »

How can one copy the session object ($_SESSION) into another object as value and not as reference? The following code snippet always does the copying as reference only:
$TEMPSESSION = $_SESSION;
So changes occur in the $_SESSION reflect in the $TEMPSESSION too; which should not happen in my case.
Please let me know how to resolve this issue!!!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Copy an object into another object as value

Post by Christopher »

First, $_SESSION is an array, not an object. Second, $_SESSION is a built-in superglobal, so you can provide the functionality you want. You will need to either only use your variable and copy values to $_SESSION, or scan $_SESSION and copy values to your variable before each use.
(#10850)
Post Reply