ID:               20240
 Updated by:       [EMAIL PROTECTED]
 Reported By:      vincent dot planchenault at atempo dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Zend Engine 2 problem
 Operating System: Linux
 PHP Version:      5.0.0-dev
 New Comment:

This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2003-04-18 17:49:29] thekid at thekid dot de

Running this script with current PHP5 gives me:

2
3
3

I guess this can be marked as fixed then?

------------------------------------------------------------------------

[2002-12-10 14:07:39] tad at tadland dot net

There appears to be a bigger problem. Consider the following code:

<?php

class test
{
    var $member;

    function test() {
        $this->member = 1;
        register_shutdown_function(array($this, 'destructor'));
    }

    function destructor() {
        print $this->member;
    }

    function add() {
        $this->member += 1;
        print $this->member."<br>\n";
    }
}


$t = new test();

$t->add();
$t->add();


?>




One might expect this code to output

2
3
3

But instead, one gets

2
3
1

So, it appears that a copy of the object is being made by
register_shutdown_function().

Tad

------------------------------------------------------------------------

[2002-11-04 03:47:39] vincent dot planchenault at atempo dot com

Using this small PHP code :

<?php

class Referenced
{
    private $m_references=0;

    function __construct()
    {
    }

    function ref()
    {
        $this->m_references++;
    }

    function unref()
    {
        $this->m_references--;
    }

    function __destruct()
    {
        echo 'in Referenced Destructor...<br>';
        echo "references = ".$this->m_references."<br>";
        echo 'out of Referenced Destructor<br>';
    }
}

class Referencer
{
    private $m_ref;

    function __construct($t)
    {
        $this->m_ref = $t;
        $t->ref();
    }

    function __destruct()
    {
        echo "in Referencer Destructor...<br>";
        $this->m_ref->unref();
        echo "out of Referencer Destructor<br>";
    }
}

$t = new Referenced();
echo 'instanciating first Referencer object...<br>';
$a = new Referencer($t);
echo 'instanciating second Referencer object...<br>';
$b = new Referencer($t);
echo 'deleting first Referencer object...<br>';
unset($a);
echo '<b>terminating</b><br>';

?>

I expected PHP to call unref() on Referenced object for the second
Referencer instance in the Referencer destructor, and then let
Referenced object be freed. This simulated output correspond to this
expectation :

instanciating first Referencer object...
instanciating second Referencer object...
deleting first Referencer object...
in Referencer Destructor...
out of Referencer Destructor
terminating
in Referencer Destructor
out of Referencer Destructor
in Referenced Destructor...
references = 0
out of Referenced Destructor...

PHP gave me this output :

instanciating first Referencer object...
instanciating second Referencer object...
deleting first Referencer object...
in Referencer Destructor...
out of Referencer Destructor
terminating
in Referenced Destructor...
references = 1
out of Referenced Destructor
in Referencer Destructor...

Fatal error: Trying to access invalid object in <blablabla>/test.php on
line 42

It seems that object instances are freed BEFORE the call of the object
destructor; I think object variables have to be freed after the
destructor call...

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=20240&edit=1

Reply via email to