Note: isset only takes on variables. Closes bug #20454

Also using var_dump() instead of print in examples.  Expanded examples a bit.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@104406 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-11-16 07:54:03 +00:00
parent 572fa58ab8
commit 918600ab1d

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/var.xml, last change in rev 1.2 -->
<refentry id="function.isset">
<refnamediv>
@ -28,22 +28,44 @@
return &false; if testing a variable that has been set to &null;. Also
note that a &null; byte (<literal>"\0"</literal>) is not equivalent to
the PHP &null; constant.
</para>
<note>
<title>Warning</title>
<para>
<function>isset</function> only works with variables as passing anything
else will result in a parse error.
</para>
</note>
<para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$a = "test";
$b = "anothertest";
echo isset ($a); // TRUE
echo isset ($a, $b); //TRUE
$var = '';
unset ($a);
echo isset ($a); // FALSE
echo isset ($a, $b); //FALSE
// This will evaluate to &true; so the text will be printed.
if (isset($var)) {
print "This var is set set so I will print.";
}
// In the next examples we'll use var_dump to output
// the return value of isset().
$a = "test";
$b = "anothertest";
var_dump( isset($a) ); // TRUE
var_dump( isset ($a, $b) ); // TRUE
unset ($a);
var_dump( isset ($a) ); // FALSE
var_dump( isset ($a, $b) ); // FALSE
$foo = NULL;
print isset ($foo); // FALSE
var_dump( isset ($foo) ); // FALSE
?>
]]>
</programlisting>
@ -55,12 +77,17 @@ $foo = NULL;
<programlisting role="php">
<![CDATA[
<?php
$a = array ('test' => 1, 'hello' => null);
echo isset ($a['test']); // TRUE
echo isset ($a['foo']); // FALSE
echo isset ($a['hello']); // FALSE
echo array_key_exists('hello', $a); // TRUE
$a = array ('test' => 1, 'hello' => NULL);
var_dump( isset ($a['test']) ); // TRUE
var_dump( isset ($a['foo']) ); // FALSE
var_dump( isset ($a['hello']) ); // FALSE
// The key 'hello' equals NULL so is considered unset
// If you want to check for NULL key values then try:
var_dump( array_key_exists('hello', $a) ); // TRUE
?>
]]>
</programlisting>