mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Update docs to be more informative on what's considered empty. And a few
more see also's. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@128272 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
ca431331de
commit
9bff141792
1 changed files with 42 additions and 28 deletions
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- splitted from ./en/functions/var.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.empty">
|
||||
<refnamediv>
|
||||
<refname>empty</refname>
|
||||
<refpurpose>Determine whether a variable is set</refpurpose>
|
||||
<refpurpose>Determine whether a variable is empty</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
@ -12,49 +12,63 @@
|
|||
<type>bool</type><methodname>empty</methodname>
|
||||
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<note>
|
||||
<para>
|
||||
<function>empty</function> is a language construct.
|
||||
</para>
|
||||
</note>
|
||||
¬e.language-construct;
|
||||
<para>
|
||||
This is the opposite of
|
||||
<function>empty</function> returns &false; if
|
||||
<parameter>var</parameter> has a non-empty or non-zero value. In
|
||||
otherwords, <literal>""</literal>, <literal>0</literal>,
|
||||
<literal>"0"</literal>, &null;, &false;, <literal>array()</literal>,
|
||||
<literal>var $var;</literal>, and objects with empty properties, are
|
||||
all considered empty. &true; is returned if <parameter>var</parameter>
|
||||
is not empty.
|
||||
</para>
|
||||
<para>
|
||||
<function>empty</function> is the opposite of
|
||||
<literal>(boolean) <parameter>var</parameter></literal>,
|
||||
except that no warning is generated when the variable is not set.
|
||||
See <link linkend="language.types.boolean.casting">converting
|
||||
to boolean</link> for more information.
|
||||
</para>
|
||||
|
||||
<!-- Returns &false; if <parameter>var</parameter> is set and has a
|
||||
non-empty or non-zero value; &true; otherwise. -->
|
||||
|
||||
<informalexample>
|
||||
<para>
|
||||
<example>
|
||||
<title>
|
||||
A simple <function>empty</function> / <function>isset</function>
|
||||
comparison.
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$var = 0;
|
||||
|
||||
if (empty($var)) { // evaluates true
|
||||
echo '$var is either 0 or not set at all';
|
||||
// Evaluates to true because $var is empty
|
||||
if (empty($var)) {
|
||||
echo '$var is either 0, empty, or not set at all';
|
||||
}
|
||||
|
||||
if (!isset($var)) { // evaluates false
|
||||
echo '$var is not set at all';
|
||||
// Evaluates as true because $var is set
|
||||
if (isset($var)) {
|
||||
echo '$var is set even though it is empty';
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
¬e.language-construct;
|
||||
|
||||
<note>
|
||||
<para>
|
||||
<function>empty</function> only checks variables as anything else will
|
||||
result in a parse error. In otherwords, the following will not work:
|
||||
<command>empty(addslashes($name))</command>.
|
||||
</para>
|
||||
</note>
|
||||
<simpara>
|
||||
Note that this is meaningless when used on anything which isn't a
|
||||
variable; i.e. <command>empty (addslashes ($name))</command> has
|
||||
no meaning since it would be checking whether something which
|
||||
isn't a variable is a variable with a &false; value.
|
||||
<!-- will even result in parse error (at least in PHP 4) -->
|
||||
</simpara>
|
||||
<simpara>
|
||||
See also <function>isset</function> and
|
||||
<function>unset</function>.
|
||||
See also <function>isset</function>,
|
||||
<function>unset</function>,
|
||||
<function>array_key_exists</function>,
|
||||
<function>count</function>, and
|
||||
<function>strlen</function>.
|
||||
</simpara>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
|
Loading…
Reference in a new issue