mirror of
https://github.com/php/doc-it.git
synced 2026-03-24 15:42:46 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@351144 c90b9560-bf6c-de11-be94-00142212c4b1
217 lines
5.8 KiB
XML
217 lines
5.8 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: f7800a7c1d2940cd986e86b76a46f6718a277853 Maintainer: pastore Status: ready -->
|
|
<!-- CREDITS: darvina -->
|
|
<refentry xml:id="function.empty" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>empty</refname>
|
|
<refpurpose>Determina se una variabile è valorizzata</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>empty</methodname>
|
|
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Determina se una variabile è da considerare vuota. Una variabile è considerata vuota se non esiste oppure se il suo valore è uguale a &false;. <function>empty</function> non genera un avviso se la variabile non esiste.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>var</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Variabile da controllare
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Prima di PHP 5.5, <function>empty</function> supporta solo variabili;
|
|
qualsiasi altra cosa si traduce in un errore di analisi. In altre parole, il
|
|
seguente comando non funziona: <command>empty(trim($name))</command>.
|
|
Invece, utilizzare <command>trim($name) == false</command>.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
Se la variabile non esiste, nessun avviso verrà generato.
|
|
Questo significa che <function>empty</function> è essenzialmente l'equivalente
|
|
conciso di <command>!isset($var) || $var == false</command>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Restituisce &false; se <parameter>var</parameter> esiste e ha un valore non vuoto e diverso da zero.
|
|
Altrimenti restituisce &true;.
|
|
</para>
|
|
<para>
|
|
I seguenti valori sono considerati vuoti:
|
|
<simplelist>
|
|
<member><literal>""</literal> (una stringa vuota)</member>
|
|
<member><literal>0</literal> (0 come intero)</member>
|
|
<member><literal>0.0</literal> (0 come numero decimale)</member>
|
|
<member><literal>"0"</literal> (0 come stringa)</member>
|
|
<member>&null;</member>
|
|
<member>&false;</member>
|
|
<member><literal>array()</literal> (un array vuoto)</member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.5.0</entry>
|
|
<entry>
|
|
<para>
|
|
<function>empty</function> ora supporta le espressioni, piuttosto che solo
|
|
variabili.
|
|
</para>
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.4.0</entry>
|
|
<entry>
|
|
<para>
|
|
Il controllo su offset non numerici di stringhe restituisce &true;.
|
|
</para>
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>
|
|
Semplici confronti
|
|
<function>empty</function> / <function>isset</function>.
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$var = 0;
|
|
|
|
// Valutata come true perché $var è vuota
|
|
if (empty($var)) {
|
|
echo '$var is either 0, empty, or not set at all';
|
|
}
|
|
|
|
// Valutata come vera perché $var è impostata
|
|
if (isset($var)) {
|
|
echo '$var is set even though it is empty';
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<example>
|
|
<title><function>empty</function> on String Offsets</title>
|
|
<para>
|
|
PHP 5.4 cambia il comportamento di <function>empty</function>
|
|
quando vengono passati offset di stringhe.
|
|
</para>
|
|
<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.53;
|
|
<screen>
|
|
<![CDATA[
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
]]>
|
|
</screen>
|
|
&example.outputs.54;
|
|
<screen>
|
|
<![CDATA[
|
|
bool(true)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.language-construct;
|
|
<note>
|
|
<para>
|
|
Quando viene utilizzata <function>empty</function> su proprietà di oggetti inaccessibili,
|
|
il metodo di overloading <link linkend="object.isset">__isset()</link>
|
|
sarà chiamato, se dichiarato.
|
|
</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">la tabella di comparazione dei tipi</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
|
|
-->
|