This is a discussion on Reference or a Copy? within the PHP Language forums, part of the PHP Programming Forums category; Hi, i'm quite new with PHP. I was wondering if i get a reference or a copy back when ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi, i'm quite new with PHP.
I was wondering if i get a reference or a copy back when i try to retrieve it at page2.php $foobar = $_SESSION['myobject']; // page1.php .... $myobject = new MyObject(); $_SESSION['myobject'] = $myobject; .... // page2.php .... $foobar = $_SESSION['myobject']; .... |
|
|||
|
That would appear to make a copy.
At the end of page2.php, you could have $_SESSION['myobject']=$foobar; to copy it back. Or you could use $_SESSION['myobject'] in place of every $foobar and it should work the same. xu wrote: > Hi, i'm quite new with PHP. > > I was wondering if i get a reference or a copy back when i try to > retrieve it at page2.php $foobar = $_SESSION['myobject']; > > // page1.php > > .... > $myobject = new MyObject(); > $_SESSION['myobject'] = $myobject; > .... > > // page2.php > > .... > $foobar = $_SESSION['myobject']; > .... |
|
|||
|
Thanks for your reply, it helped me alot with my insight of when php's
object reference is in place and when not. I'm now going to test the & to see if i'm getting a reference or not. // page2.php .... $foobar =& $_SESSION['myobject']; ? .... neur0maniak wrote: > That would appear to make a copy. > > At the end of page2.php, you could have $_SESSION['myobject']=$foobar; > to copy it back. Or you could use $_SESSION['myobject'] in place of > every $foobar and it should work the same. > > > xu wrote: > >> Hi, i'm quite new with PHP. >> >> I was wondering if i get a reference or a copy back when i try to >> retrieve it at page2.php $foobar = $_SESSION['myobject']; >> >> // page1.php >> >> .... >> $myobject = new MyObject(); >> $_SESSION['myobject'] = $myobject; >> .... >> >> // page2.php >> >> .... >> $foobar = $_SESSION['myobject']; >> .... |