cvs: phpdoc-es /language references.xml

From: Date: Sun, 11 May 2003 21:51:51 +0000
Subject: cvs: phpdoc-es /language references.xml
Groups: php.doc.es 
Request: Send a blank email to doc-es+get-185@lists.php.net to get a copy of this message
webstudio Sun May 11 17:51:51 2003 EDT Modified files: /phpdoc-es/language references.xml Log: Trad. de Referencias Terminada

Index: phpdoc-es/language/references.xml diff -u phpdoc-es/language/references.xml:1.6 phpdoc-es/language/references.xml:1.7 --- phpdoc-es/language/references.xml:1.6 Fri May 9 17:41:20 2003 +++ phpdoc-es/language/references.xml Sun May 11 17:51:51 2003 @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> +<!-- En-Revision: 1.24 Maintainer: webstudio Status: ready --> <chapter id="language.references"> <title>Explicando las Referencias</title> <sect1 id="language.references.whatare"> @@ -31,45 +32,47 @@ significa que <varname>$a</varname> y <varname>$b</varname> apuntan a la misma variable. <note> - <para> - <varname>$a</varname> y <varname>$b</varname> son completamente iguales, no es que <varname>$a</varname> esté apuntando a + <para> + <varname>$a</varname> y <varname>$b</varname> son completamente iguales, no es que <varname>$a</varname> est&eacute; apuntando a <varname>$b</varname> o viceversa, sino que tanto <varname>$a</varname> como <varname>$b</varname> apuntan al mismo lugar. </para> - </note> + </note> </para> <para> - La misma sintaxis puede ser utilizada con funciones, que devuelven Referencias, - y con el operador <literal>new</literal> (en PHP 4.0.4 o mayor): + La misma sint&aacute;xis puede ser utilizada con funciones, que devuelven Referencias, + y con el operador <literal>new</literal> (en PHP 4.0.4 o superior): <informalexample> - <programlisting role="php"><![CDATA[ + <programlisting role="php"><![CDATA[ $bar =& new fooclass(); $foo =& find_var ($bar); ]]></programlisting> -</informalexample> + </informalexample> </para> <note> <para> - Not using the <literal>&amp;</literal> operator causes a copy of the - object to be made. If you use <literal>$this</literal> in the class it - will operate on the current instance of the class. The assignment without - <literal>&amp;</literal> will copy the instance (i.e. the object) and - <literal>$this</literal> will operate on the copy, which is not always - what is desired. Usually you want to have a single instance to work with, - due to performance and memory consumption issues. - </para> + El no utilizar el operador <literal>&amp;</literal> causa que + el objeto sea copiado en memoria. Si utilizamos <literal>$this</literal> + en la clase, entonces actuaremos sobre la instancia actual de + la clase. Las asignaciones sin <literal>&amp;</literal> har&aacute;n una + copia de la instancia (por ejemplo, del objeto) y <literal>$this</literal> + operar&aacute; en la copia, lo que no siempre es el comportamiento + deseado. Usualmente se desea utilizar una sola instancia, debido + a razones de memoria y performance de la aplicaci&oacute;n. + </para> <para> - While you can use the <literal>@</literal> operator to - <emphasis>mute</emphasis> any errors in the constructor when using it as - <literal>@new</literal>, this does not work when using the - <literal>&amp;new</literal> statement. This is a limitation of the Zend - Engine and will therefore result in a parser error. + Mientras que se puede utilizar <literal>@</literal> para + <emphasis>silenciar</emphasis> cualquier error en el constructor + utilizando <literal>@new</literal>, esto no funciona cuando + utilizamos <literal>&amp;new</literal>. Esto es una limitaci&oacute;n + del Zend Engine y por lo tanto, resultar&aacute; en un error de sint&aacute;xis. </para> </note> <para> - The second thing references do is to pass variables - by-reference. This is done by making a local variable in a function and - a variable in the calling scope reference to the same content. Example: + Otro uso que se le puede dar a las referencias es el traspaso de variables + por-referencia. Esto se logra haciendo que una variable 'local' a la + funci&oacute;n y una variable en el script 'referencien' al mismo contenido. + Por ejemplo: <informalexample> <programlisting role="php"><![CDATA[ function foo (&$var) @@ -81,20 +84,20 @@ foo ($a); ]]></programlisting> </informalexample> - will make <varname>$a</varname> to be 6. This happens because in - the function <varname>foo</varname> the variable - <varname>$var</varname> refers to the same content as - <varname>$a</varname>. See also more detailed explanations about <link linkend="language.references.pass">passing by reference</link>. + har&aacute; que <varname>$a</varname> valga 6. Esto es posible porque en + la funci&oacute; <varname>foo</varname>, la variable <varname>$var</varname> + 'referencia' al mismo contenido que la variable <varname>$a</varname>. M&aacute;s + informaci&oacute;n acerca de <link linkend="language.references.pass">paso por referencia</link>. </para> <simpara> - The third thing reference can do is <link linkend="language.references.return">return by reference</link>. + Un tercer uso de las referencias es el <link linkend="language.references.return">retorno por referencia</link>. </simpara> </sect1> <sect1 id="language.references.arent"> - <title>What References Are Not</title> + <title>Lo que las Referencias no son</title> <para> - As said before, references aren't pointers. That means, the - following construct won't do what you expect: + Como se ha mencionado antes, las Referencias NO son punteros. + Esto significa que el siguiente ejemplo no har&aacute; lo que se espera: <informalexample> <programlisting role="php"><![CDATA[ function foo (&$var) @@ -106,23 +109,21 @@ </informalexample> </para> <simpara> - What happens is that <varname>$var</varname> in - <varname>foo</varname> will be bound with - <varname>$bar</varname> in caller, but then it will be - re-bound with <varname>$GLOBALS["baz"]</varname>. There's no way - to bind <varname>$bar</varname> in the calling scope to something else - using the reference mechanism, since <varname>$bar</varname> is not - available in the function <varname>foo</varname> (it is represented by - <varname>$var</varname>, but <varname>$var</varname> has only - variable contents and not name-to-value binding in the calling - symbol table). + Lo que ocurrir&aacute; aqu&iacute; es que <varname>$var</varname> en <varname>foo</varname> + ser&aacute; 'ligada' con <varname>$bar</varname> al momento de llamar a la funci&oacute;n. + Pero luego ser&aacute; 're-ligada' con <varname>$GLOBALS["baz"]</varname>. No existe + manera de ligar <varname>$bar</varname> en el &aacute;mbito global del script con alguna + otra cosa utilizando el mecanismo de Referencias, ya que <varname>$bar</varname> + no existe dentro de <varname>foo</varname> (est&aacute; representado por <varname>$var</varname>, + pero <varname>$var</varname> solo est&aacute; ligado por el contenido, no por el nombre + en la tabla de s&iacute;mbolos). </simpara> </sect1> <sect1 id="language.references.pass"> - <title>Passing by Reference</title> + <title>Paso de variables por Referencia</title> <para> - You can pass variable to function by reference, so that function could modify - its arguments. The syntax is as follows: + Podemos pasar variables a una funci&oacute;n por referencia, para que &eacute;sta pueda modificar + sus argumentos. La sint&aacute;xis es la siguiente : <informalexample> <programlisting role="php"><![CDATA[ function foo (&$var) @@ -132,29 +133,30 @@ $a=5; foo ($a); -// $a is 6 here +// $a ser&aacute; 6 aqui ]]></programlisting> </informalexample> - Note that there's no reference sign on function call - only on - function definition. Function definition alone is enough to - correctly pass the argument by reference. + Notar que no hay signo de referencia en la llamada a la funci&oacute;n - + solo en la definici&oacute;n de la misma. Colocar el signo de referencia + solo en la definici&oacute;n de la funci&oacute;n alcanza para pasar correctamente + el argumento por referencia. </para> <para> - Following things can be passed by reference: + La lista siguiente indica que puede ser pasado por referencia: <itemizedlist> <listitem> <simpara> - Variable, i.e. <literal>foo($a)</literal> + Variables, por ejemplo <literal>foo($a)</literal> </simpara> </listitem> <listitem> <simpara> - New statement, i.e. <literal>foo(new foobar())</literal> + Operador New, por ejemplo <literal>foo(new foobar())</literal> </simpara> </listitem> <listitem> <para> - Reference, returned from a function, i.e.: + Referencias, devueltas por una funci&oacute;n: <informalexample> <programlisting role="php"><![CDATA[ function &bar() @@ -165,69 +167,71 @@ foo(bar()); ]]></programlisting> </informalexample> - See also explanations about <link linkend="language.references.return">returning by reference</link>. + Se recomienda leer tambi&eacute;n la explicaci&oacute;n sobre <link linkend="language.references.return">retorno por referencia</link>. </para> </listitem> </itemizedlist> </para> <para> - Any other expression should not be passed by reference, as the - result is undefined. For example, the following examples of passing - by reference are invalid: - <informalexample> - <programlisting role="php"><![CDATA[ -function bar() // Note the missing & + Cualquier otro tipo de expresi&oacute;n no deber&iacute;a pasarse por referencia, + ya que el resultado ser&iacute;a indefinido. Los ejemplos de paso + por referencia siguientes son inv&aacute;lidos: + <informalexample> + <programlisting role="php"><![CDATA[ +function bar() // Notar que falta & { $a = 5; return $a; } foo(bar()); -foo($a = 5) // Expression, not variable -foo(5) // Constant, not variable -]]></programlisting> - </informalexample> - These requirements are for PHP 4.0.4 and later. +foo($a = 5) // Expresi&oacute;n, no variable +foo(5) // Constante, no variable +]]> + </programlisting> + </informalexample> + Estos requerimientos son para PHP 4.0.4 y superior. </para> </sect1> <sect1 id="language.references.return"> - <title>Returning References</title> + <title>Retorno por Referencia</title> <para> - Returning by-reference is useful when you want to use a function - to find which variable a reference should be bound to. When - returning references, use this syntax: - <informalexample> + Devolver por Referencia es muy &uacute;til cuando se quiere utilizar una funci&oacute;n + para averiguar a que variable debe estar una referencia ligada. Cuando + se devuelve por referencia, se debe utilizar esta sint&aacute;xis: + <informalexample> <programlisting role="php"><![CDATA[ -function &find_var ($param) +function &encontrar_var ($param) { - ...code... - return $found_var; + ...codigo... + return $var_encontrada; } -$foo =& find_var ($bar); +$foo =& encontrar_var ($bar); $foo->x = 2; ]]></programlisting> - </informalexample> - In this example, the property of the object returned by the - <varname>find_var</varname> function would be set, not the - copy, as it would be without using reference syntax. + </informalexample> + En este ejemplo, el atributo del objeto devuelto por la funci&oacute;n + <varname>encontrar_var</varname> fue asignado, no ya en + la copia, como habr&iacute;a sucedido si no se utilizaba la sint&aacute;xis de + referencias. </para> <note> <simpara> - Unlike parameter passing, here you have to use - <literal>&amp;</literal> in both places - to indicate that you - return by-reference, not a copy as usual, and to indicate that - reference binding, rather than usual assignment, should be done - for <varname>$foo</varname>. + A diferencia del paso de par&aacute;metros, aqu&iacute; se debe utilizar + <literal>&amp;</literal> en ambos lugares - para indicar que + se pretende devolver por referencia ( y no una copia, como + usualmente sucede) y que adem&aacute;s esa referencia sea + 'ligada' a una variable, y no solo asignada. </simpara> </note> </sect1> <sect1 id="language.references.unset"> - <title>Unsetting References</title> + <title>Borrando Referencias</title> <para> - When you unset the reference, you just break the binding between - variable name and variable content. This does not mean that - variable content will be destroyed. For example: + Cuando de borra una referencia, solo se rompe esa uni&oacute;n entre + el nombre de la variable y el contenido. Esto no significa que el contenido + haya sido destruido. Por ejemplo : <informalexample> <programlisting role="php"><![CDATA[ $a = 1; @@ -235,29 +239,29 @@ unset ($a); ]]></programlisting> </informalexample> - won't unset <varname>$b</varname>, just <varname>$a</varname>. + no destruir&iacute;a <varname>$b</varname>, solo <varname>$a</varname>. </para> <simpara> - Again, it might be useful to think about this as analogous to Unix - <command>unlink</command> call. + Nuevamente, ser&iacute;a &uacute;til pensar el tema de las referencias como una + analog&iacute;a al comando <command>unlink</command> de Unix. </simpara> </sect1> <sect1 id="language.references.spot"> - <title>Spotting References</title> + <title>M&aacute;s Referencias</title> <simpara> - Many syntax constructs in PHP are implemented via referencing - mechanisms, so everything told above about reference binding also - apply to these constructs. Some constructs, like passing and - returning by-reference, are mentioned above. Other constructs that - use references are: + Muchas construcciones sint&aacute;cticas en PHP son implementadas utilizando + el mecanismo referencial, de manera que todo lo dicho anteriormente sobre + las referencias tambi&eacute;n se aplica a estas construcciones. Algunas de ellas, + como pasar o retornar por referencia, se mencionaron antes. Otras + construcciones que utilizan referencias son: </simpara> <sect2 id="references.global"> <title> - <literal>global</literal> References</title> + Referencias <literal>globales</literal></title> <para> - When you declare variable as <command>global $var</command> you - are in fact creating reference to a global variable. That means, - this is the same as: + Cuando declaramos una variable como <command>global $var</command> + en realidad estamos creando una referencia a una variable global. Esto + significa, que es lo mismo que hacer : <informalexample> <programlisting role="php"><![CDATA[ $var =& $GLOBALS["var"]; @@ -265,8 +269,8 @@ </informalexample> </para> <simpara> - That means, for example, that unsetting <varname>$var</varname> - won't unset global variable. + De esta manera, por ejemplo, si borramos <varname>$var</varname> + no estar&iacute;amos borrando la variable global. </simpara> </sect2> <sect2 id="references.this"> @@ -274,8 +278,8 @@ <literal>$this</literal> </title> <simpara> - In an object method, <varname>$this</varname> is always reference - to the caller object. + En un m&eacute;todo de objeto, <varname>$this</varname> es siempre una + referencia al objeto que contiene el m&eacute;todo. </simpara> </sect2> </sect1>
« previous php.doc.es (#185) next »