mirror of
https://github.com/php/doc-es.git
synced 2026-04-24 23:58:06 +02:00
320a701c77
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@336084 c90b9560-bf6c-de11-be94-00142212c4b1
293 lines
6.3 KiB
XML
293 lines
6.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: afc3f34c682418a582b0f9199db0bac4a087821f Maintainer: yago Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.unset" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>unset</refname>
|
|
<refpurpose>Destruye una variable especificada</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>void</type><methodname>unset</methodname>
|
|
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>unset</function> destruye las variables especificadas.
|
|
</para>
|
|
<para>
|
|
El comportamiento de <function>unset</function> dentro de una función
|
|
puede variar dependiendo de qué tipo de variable que se está tratando de destruir.
|
|
</para>
|
|
<para>
|
|
Si una variable global es <function>unset</function> dentro de
|
|
una función, solo la variable local es destruida. La variable en el
|
|
entorno de la llamada mantendrá el mismo valor anterior a la llamada a
|
|
<function>unset</function>.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function destruir_foo()
|
|
{
|
|
global $foo;
|
|
unset($foo);
|
|
}
|
|
|
|
$foo = 'bar';
|
|
destruir_foo();
|
|
echo $foo;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
&example.outputs;
|
|
<para>
|
|
<informalexample>
|
|
<screen>
|
|
<![CDATA[
|
|
bar
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
Si desea aplicar <function>unset</function> a una variable global
|
|
dentro de una función, puede usar la matriz
|
|
<varname>$GLOBALS</varname> para hacerlo:
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function foo()
|
|
{
|
|
unset($GLOBALS['bar']);
|
|
}
|
|
|
|
$bar = "algo";
|
|
foo();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
Si una variable que se pasa POR REFERENCIA es
|
|
<function>unset</function> dentro de una función, sólo la variable local
|
|
es destruida. La variable en el entorno de la llamada
|
|
mantendrá el mismo valor anterior a la llamada a <function>unset</function>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function foo(&$bar)
|
|
{
|
|
unset($bar);
|
|
$bar = "blah";
|
|
}
|
|
|
|
$bar = 'algo';
|
|
echo "$bar\n";
|
|
|
|
foo($bar);
|
|
echo "$bar\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
&example.outputs;
|
|
<para>
|
|
<informalexample>
|
|
<screen>
|
|
<![CDATA[
|
|
algo
|
|
algo
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
Si una variable estática es <function>unset</function> dentro de una
|
|
función, <function>unset</function> destruye la variable únicamente en el
|
|
contexto del resto de una función. Las llamadas siguientes recuperarán
|
|
el valor previo de una variable.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function foo()
|
|
{
|
|
static $bar;
|
|
$bar++;
|
|
echo "Antes de unset: $bar, ";
|
|
unset($bar);
|
|
$bar = 23;
|
|
echo "Después de unset: $bar\n";
|
|
}
|
|
|
|
foo();
|
|
foo();
|
|
foo();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
&example.outputs;
|
|
<para>
|
|
<informalexample>
|
|
<screen>
|
|
<![CDATA[
|
|
Antes de unset: 1, después de unset: 23
|
|
Antes de unset: 2, después de unset: 23
|
|
Antes de unset: 3, después de unset: 23
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>var</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La variable a ser destruida.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>...</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Otra variable...
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.void;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>unset</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// destruir una sola variable
|
|
unset($foo);
|
|
|
|
// destruir un solo elemento de una matriz
|
|
unset($bar['quux']);
|
|
|
|
// destruir más de una variable
|
|
unset($foo1, $foo2, $foo3);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Usando el forzado a <literal>(unset)</literal></title>
|
|
<para>
|
|
El forzado a <literal>(unset)</literal> a menudo se confunde con
|
|
la función <function>unset</function>. El forzado <literal>(unset)</literal>
|
|
sólo sirve como una conversión de tipo <literal>NULL</literal>. Esto no altera
|
|
la variable que se está forzando.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$name = 'Felipe';
|
|
|
|
var_dump((unset) $name);
|
|
var_dump($name);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
NULL
|
|
string(6) "Felipe"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.language-construct;
|
|
<note>
|
|
<para>
|
|
Es posible remover incluso propiedades de objetos visibles en el
|
|
contexto actual.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
No es posible remover <literal>$this</literal> dentro de un método
|
|
de objeto a partir de PHP 5.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
Cuando se utiliza <function>unset</function> sobre las propiedades de objetos inaccesibles,
|
|
el método de sobrecarga <link linkend="object.unset">__unset()</link>
|
|
será llamado, si se declara.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>isset</function></member>
|
|
<member><function>empty</function></member>
|
|
<member><link linkend="object.unset">__unset()</link></member>
|
|
<member><function>array_splice</function></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
|
|
-->
|