Bluehost.com Web Hosting $6.95

Reference or a Copy?

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-22-2004
xu
 
Posts: n/a
Default Reference or a Copy?

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'];
....
Reply With Quote
  #2 (permalink)  
Old 10-22-2004
neur0maniak
 
Posts: n/a
Default Re: Reference or a Copy?

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'];
> ....

Reply With Quote
  #3 (permalink)  
Old 10-25-2004
Huabi Xu
 
Posts: n/a
Default Re: Reference or a Copy?

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'];
>> ....

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:07 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0