Doc #55164 [Ana->Csd]: Unclear/incorrect description of "casting to null"
| From: | frozenfire@php.net | Date: | Thu, 12 Jan 2012 05:22:58 +0000 |
| Subject: | Doc #55164 [Ana->Csd]: Unclear/incorrect description of "casting to null" | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7771@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55164&edit=1
ID: 55164
Updated by: frozenfire@php.net
Reported by: deceze at gmail dot com
Summary: Unclear/incorrect description of "casting to null"
-Status: Analyzed
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: frozenfire
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2012-01-12 05:22:33] frozenfire@php.net
Automatic comment from SVN on behalf of frozenfire
Revision: http://svn.php.net/viewvc/?view=revision&revision=322117
Log: Clarified highly-misleading (unset) casting example. Resolves bug #55164.
------------------------------------------------------------------------
[2012-01-12 05:07:30] frozenfire@php.net
Rather, it seems that the confusion here is with what (unset) casting does. It's
not meant to unset a variable, but rather to cast it to null. That casting type
exists purely for completeness, and you may as well just use NULL.
The way to undefine a variable is through the language construct unset. Perhaps
I'll make a note in the unset() function reference that it's unrelated to unset-
casting, and remove that errant example.
------------------------------------------------------------------------
[2012-01-12 04:21:45] frozenfire at thefrozenfire dot com
I believe the major distinction between the various states of the variable has to
do not with the value, but rather its presence in the symbol table. When you
assign null to a variable, it is still in the symbol table. When you cast it to
unset, it's still in the symbol table until the operation finishes. When you
unset it, it's removed from the symbol table, thus becoming "undefined".
I'll see about confirming my suspicions through inspection of the source.
------------------------------------------------------------------------
[2011-07-08 21:53:07] deceze at gmail dot com
Yes, but:
error_reporting(E_ALL);
var_dump($undefined);
$foo = 'bar';
$foo = (unset)$foo; // or $foo = null
var_dump($foo);
unset($foo);
var_dump($foo);
Outputs:
Notice: Undefined variable: undefined
NULL
NULL
Notice: Undefined variable: foo
NULL
null is the default value for undefined variables, but undefined/"removed"
variables are not the same as variables with a null value.
------------------------------------------------------------------------
[2011-07-08 21:47:26] philip@php.net
Simply this:
<?php
var_dump($undefined);
?>
Outputs NULL.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55164
--
Edit this bug report at https://bugs.php.net/bug.php?id=55164&edit=1