Re: Reassigning variable to new object destroys old one?



On Apr 30, 12:40 pm, Toby A Inkster <usenet200...@xxxxxxxxxxxxxxxxx>
wrote:
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) ARCShttp://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux

Right -- so, like I said, the object is destroyed when nothing is
referencing it.

.



Relevant Pages

  • Re: Reassigning variable to new object destroys old one?
    ... When you assign the second instance to $x, ... referencing the first instance. ... public function __construct ...
    (comp.lang.php)
  • Re: Reassigning variable to new object destroys old one?
    ... ZeldorBlat wrote: ... When you assign the second instance to $x, ... referencing the first instance. ...
    (comp.lang.php)
  • Re: Reassigning variable to new object destroys old one?
    ... I don't call unset()) PHP is destroying the variable every other ... The object is automatically destroyed when nothing is referencing it. ... When you assign the second instance to $x, ... referencing the first instance. ...
    (comp.lang.php)
  • Re: Array Function
    ... You're referencing "FieldArray" in your function, and for the life of me, I ... > Public Function FieldArrayas arraylist ... > Private Sub Page_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: query variable
    ... Instead of referencing the variable by name, ... reference a public function that simply ... Tom Ellison ... >WITH OWNERACCESS OPTION; ...
    (microsoft.public.access.queries)