Re: Reassigning variable to new object destroys old one?
- From: Toby A Inkster <usenet200703@xxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 17:40:40 +0100
ZeldorBlat wrote:
The object is automatically destroyed when nothing is referencing it.
When you assign the second instance to $x, there is nothing left
referencing the first instance.
This isn't strictly true. There may still be other references to the
object floating about.
class Foo
{
public static $primary_instance = NULL;
public $val;
public function __construct ($n)
{
if (!isset(self::$primary_instance))
self::$primary_instance = $this;
$this->val = $n;
}
public function carp ()
{
echo $this->val . "\n";
}
}
$x = new Foo(123); // First Foo object
$x = new Foo(456); // Replacement Foo object
$x->carp();
// But the first one is still hanging around
// because another reference to it exists.
Foo::$primary_instance->carp();
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
.
- Follow-Ups:
- Re: Reassigning variable to new object destroys old one?
- From: ZeldorBlat
- Re: Reassigning variable to new object destroys old one?
- References:
- Reassigning variable to new object destroys old one?
- From: woger151
- Re: Reassigning variable to new object destroys old one?
- From: ZeldorBlat
- Reassigning variable to new object destroys old one?
- Prev by Date: Re: Manipulating binary data
- Next by Date: Re: Reassigning variable to new object destroys old one?
- Previous by thread: Re: Reassigning variable to new object destroys old one?
- Next by thread: Re: Reassigning variable to new object destroys old one?
- Index(es):
Relevant Pages
|