php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29428 Error or missing overview of unset() function
Submitted: 2004-07-28 14:07 UTC Modified: 2004-07-28 15:56 UTC
From: kingoleg at mail dot ru Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
 [2004-07-28 14:07 UTC] kingoleg at mail dot ru
Description:
------------
In http://ua2.php.net/unset nothing said about how work unset() on local variables (PASSED BY REFERENCE or NOT).

unset() always "destroy" variables in local area. See code 1.

May be would be good to write, that for variable PASSED BY REFERENCE we can use operation = null to unset variable. See code 2.

Reproduce code:
---------------
<?php
function a() {
$foo = 'ok';
b($foo);
var_dump($foo);
}
function b(&$foo) {
$foo = 'not ok';
unset($foo);
}
a();
?>

<?php
function a() {
$foo = 'ok';
b($foo);
var_dump($foo);
}
function b(&$foo) {
$foo = 'not ok';
$foo=null;
}
a();
var_dump($b);
?>

Expected result:
----------------
For code 1. 
One of tree:

1. 'ok'
2. 'not ok'
3. variable $foo is null (not setted)

For code 2.

NULL NULL

Actual result:
--------------
'not ok'

NULL NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-28 15:56 UTC] vrana@php.net
It's described pretty well, there's even example on this. Assigning null is slightly different from unsetting (e.g. variable stays in parent array with null value).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC