php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22655 problems with unset
Submitted: 2003-03-12 02:15 UTC Modified: 2003-04-23 05:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: stanislav at shramko dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.0 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stanislav at shramko dot com
New email:
PHP Version: OS:

 

 [2003-03-12 02:15 UTC] stanislav at shramko dot com
I was very discouraged about the behavior of unset() function with variables which are
contained in objects in the same time. Also I'm slightly mad about references to NULL and so on.

<?php

// two test classes

class a
{

    var $a = null;

    function a( &$b )
    {
        $this->a = &$b;
    }

}

class b
{
    var $b = 5;
}

// ---------- the main part ------------

// alas, I need to use destructors

$b = &new b();
$a = &new a( $b );
var_dump( $a ); // checking the object's state
$b->b = 3; // changing it
var_dump( $a ); // Note that value was changed...
unset( $b ); // what are we waiting for?
var_dump( $a ); // but the object's field wasn't affected
$b = null;
var_dump( $a ); // there's no way to destroy this blamed property

echo "------------------------------------------------------------\n";
// but in case if we will try to assign a null value to this field whilst 
// the object is in it's initial state, we're getting another results

$b = &new b();
$a = &new a( $b );
var_dump( $a );
$b->b = 3;
var_dump( $a ); // Note that value was changed...
$b = null;
var_dump( $a ); // I see, it's a great way to dispose a field of an object :)
// this reference to NULL looks pretty well, isn't it? :)

?>

I've lost the sence of the whole situation at this point.

Regards,
Stanislav.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-12 17:15 UTC] sniper@php.net
And what did you expect the output to be?

 [2003-03-12 18:54 UTC] stanislav at shramko dot com
I thought that the variable should be unset in the class as well, cause it was passed into constructor by reference. Also it is disposed in the global scope so should be removed from everywhere. Now it seems that the variable is unset in the global scope, not in local ones. Such behavior of PHP seems not very predicable to me. 
The only solution I found is to assign a null value to the variable manually. It looks like a workaround though, not like the right way to do things.
 [2003-04-23 05:01 UTC] sniper@php.net
It's just how it's supposed to work.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 20:01:29 2024 UTC