1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-25 16:22:18 +01:00
Files
archived-doc-ru/reference/var/functions/empty.xml
2024-01-12 16:59:32 +03:00

152 lines
5.3 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 4a07033f7ac5ab121357051cc94ec48b9f6f58fc Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.empty" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>empty</refname>
<refpurpose>Проверяет, пуста ли переменная</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>empty</methodname>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
</methodsynopsis>
<para>
Проверяет, считается ли переменная пустой. Переменная считается пустой, если она не существует или её значение равно &false;.
Языковая конструкция <function>empty</function> не генерирует предупреждение, если переменная не существует.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>var</parameter></term>
<listitem>
<para>
Проверяемая переменная.
</para>
<para>
Если переменная не существует, предупреждение не генерируется.
То есть конструкция <function>empty</function>
это краткий эквивалент конструкции <command>!isset($var) || $var == false</command>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает &true;, если переданная в параметр <parameter>var</parameter> переменная не существует,
содержит пустое значение или равно нулю, то есть ложно,
подробнее о приведении значений к логическим типам рассказано
в параграфе <link linkend="language.types.boolean.casting">преобразование в логический тип</link>.
В остальных случаях возвращает &false;.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>
Простое сравнение языковых конструкций <function>empty</function> и <function>isset</function>.
</title>
<programlisting role="php">
<![CDATA[
<?php
$var = 0;
// Принимает значение true, потому что переменная $var содержит пустое значение
if (empty($var)) {
echo '$var или 0, или пусто, или вообще не определена';
}
// Принимает значение true, потому что переменная $var определена
if (isset($var)) {
echo '$var определена, даже если она пустая';
}
?>
]]>
</programlisting>
</example>
</para>
<example>
<title>Конструкция <function>empty</function> и строковые индексы</title>
<programlisting role="php">
<![CDATA[
<?php
$expected_array_got_string = 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
]]>
</screen>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.language-construct;
<note>
<para>
При вызове языковой конструкции <function>empty</function>
на недоступных (необъявленных, защищённых или закрытых) свойствах объекта
вызывается метод перегрузки — <link linkend="object.isset">__isset()</link>,
если он определён.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>isset</function></member>
<member><link linkend="object.isset">__isset()</link></member>
<member><function>unset</function></member>
<member><function>array_key_exists</function></member>
<member><function>count</function></member>
<member><function>strlen</function></member>
<member><link linkend="types.comparisons">Таблица сравнения типов</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->