Re: [PHP] unsetting object references

2002-04-17 Thread Robert Cummings

Erik Price wrote:
> 
> On Wednesday, April 17, 2002, at 03:59  PM, Robert Cummings wrote:
> 
> > Now if what you meant was the following:
> >
> > $objectFoo = new MyObject();
> > $objectFee = &$objectFoo;
> >
> > unset( $objectFoo );
> >
> > Then the object shouldn't be deleted since $objectFee is still
> > referencing
> > it. You will just break the reference. Correct me if I'm wrong *chuckle*
> 
> What if I did
> 
> $objectFoo = new MyObject;
> $objectFee = $objectFoo;
> 
> unset($objectFoo);
> 
> essentially, does PHP make a (deep|shallow) copy of an object in this
> reassignment, or is it just creating a new reference?

Should be a copy, and it should be safe... though I recall a discussion
last week that displayed an interesting bug (feature?).

Cheers,
Rob.
-- 
.-.
| Robert Cummings |
:-`.
| Webdeployer - Chief PHP and Java Programmer  |
:--:
| Mail  : mailto:[EMAIL PROTECTED] |
| Phone : (613) 731-4046 x.109 |
:--:
| Website : http://www.webmotion.com   |
| Fax : (613) 260-9545 |
`--'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] unsetting object references

2002-04-17 Thread Erik Price


On Wednesday, April 17, 2002, at 03:59  PM, Robert Cummings wrote:

> Now if what you meant was the following:
>
> $objectFoo = new MyObject();
> $objectFee = &$objectFoo;
>
> unset( $objectFoo );
>
> Then the object shouldn't be deleted since $objectFee is still 
> referencing
> it. You will just break the reference. Correct me if I'm wrong *chuckle*

What if I did

$objectFoo = new MyObject;
$objectFee = $objectFoo;

unset($objectFoo);

essentially, does PHP make a (deep|shallow) copy of an object in this 
reassignment, or is it just creating a new reference?


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] unsetting object references

2002-04-17 Thread Robert Cummings

Erik Price wrote:
> 
> Hey, sorry to bother you all but I have another obscure question about
> objects in PHP (yes I really do care about the answer)...
> 
> I'm simply wondering if I unset() a reference to an object, whether or
> not it destroys that object, if there are other references to it that
> still exist.
> 
> $_SESSION['object'] = serialize($object);
> 
> (in another script:)
> 
> $object = unserialize($_SESSION['object']);
> // do some stuff with $object
> unset($object);
> 
> What's going on with my $_SESSION['object'] ?


In the example you are providing $object and $_SESSION['object'] aren't
even the same thing and unless something else is referencing $object
then $object will be deleted.

Now if what you meant was the following:

$objectFoo = new MyObject();
$objectFee = &$objectFoo;

unset( $objectFoo );

Then the object shouldn't be deleted since $objectFee is still referencing
it. You will just break the reference. Correct me if I'm wrong *chuckle*

Cheers,
Rob.
-- 
.-.
| Robert Cummings |
:-`.
| Webdeployer - Chief PHP and Java Programmer  |
:--:
| Mail  : mailto:[EMAIL PROTECTED] |
| Phone : (613) 731-4046 x.109 |
:--:
| Website : http://www.webmotion.com   |
| Fax : (613) 260-9545 |
`--'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] unsetting object references

2002-04-17 Thread Erik Price

Hey, sorry to bother you all but I have another obscure question about 
objects in PHP (yes I really do care about the answer)...


I'm simply wondering if I unset() a reference to an object, whether or 
not it destroys that object, if there are other references to it that 
still exist.

$_SESSION['object'] = serialize($object);

(in another script:)

$object = unserialize($_SESSION['object']);
// do some stuff with $object
unset($object);

What's going on with my $_SESSION['object'] ?


Erik







Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php