cvs: phpdoc /en/language references.xml

From: Date: Mon, 29 Dec 2008 02:48:17 +0000
Subject: cvs: phpdoc /en/language references.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2865@lists.php.net to get a copy of this message
danbrown Mon Dec 29 02:48:17 2008 UTC Modified files: /phpdoc/en/language references.xml Log: Rewrote many parts throughout to fix grammar and structure.

http://cvs.php.net/viewvc.cgi/phpdoc/en/language/references.xml?r1=1.50&r2=1.51&diff_format=u Index: phpdoc/en/language/references.xml diff -u phpdoc/en/language/references.xml:1.50 phpdoc/en/language/references.xml:1.51 --- phpdoc/en/language/references.xml:1.50 Mon Nov 12 22:54:49 2007 +++ phpdoc/en/language/references.xml Mon Dec 29 02:48:17 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.50 $ --> +<!-- $Revision: 1.51 $ --> <chapter xml:id="language.references" xmlns="http://docbook.org/ns/docbook"> <title>References Explained</title> @@ -10,9 +10,9 @@ by different names. They are not like C pointers; instead, they are symbol table aliases. Note that in PHP, variable name and variable content are different, so the same content can have different names. - The most close analogy is with Unix filenames and files - - variable names are directory entries, while variable contents is - the file itself. References can be thought of as hardlinking in + The closest analogy is with Unix filenames and files - + variable names are directory entries, while variable content is + the file itself. References can be likened to hardlinking in Unix filesystem. </simpara> </sect1> @@ -36,22 +36,22 @@ <note> <para> <varname>$a</varname> and <varname>$b</varname> are completely - equal here, that's not <varname>$a</varname> is pointing to - <varname>$b</varname> or vice versa, that's - <varname>$a</varname> and <varname>$b</varname> pointing to the + equal here. <varname>$a</varname> is not pointing to + <varname>$b</varname> or vice versa. + <varname>$a</varname> and <varname>$b</varname> are pointing to the same place. </para> </note> </para> <note> <para> - If array with references is copied, its values are not dereferenced. + If arrays with references are copied, their values are not dereferenced. This is valid also for arrays passed by value to functions. </para> </note> <note> <para> - If you assign, pass or return an undefined variable by reference, + If you assign, pass, or return an undefined variable by reference, it will get created. <example> <title>Using references with undefined variables</title> @@ -76,8 +76,8 @@ </para> </note> <para> - The same syntax can be used with functions, that return references, - and with <literal>new</literal> operator (in PHP 4.0.4 and later): + The same syntax can be used with functions that return references, + and with the <literal>new</literal> operator (in PHP 4.0.4 and later): <informalexample> <programlisting role="php"> <![CDATA[ @@ -88,9 +88,9 @@ ]]> </programlisting> </informalexample> - Since PHP 5, <link linkend="language.oop5.basic.new">new</link> return - reference automatically so using <literal>=&amp;</literal> in this - context is deprecated and produces E_STRICT level message. + Since PHP 5, <link linkend="language.oop5.basic.new">new</link> returns + a reference automatically, so using <literal>=&amp;</literal> in this + context is deprecated and produces an E_STRICT message. </para> <note> <para> @@ -107,7 +107,7 @@ <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. + Engine and will therefore result in a parse error. </para> </note> <warning> @@ -116,7 +116,7 @@ inside a function, the reference will be visible only inside the function. You can avoid this by using the <varname>$GLOBALS</varname> array. <example> - <title>Referencing global variables inside function</title> + <title>Referencing global variables inside functions</title> <programlisting role="php"> <![CDATA[ <?php @@ -142,7 +142,7 @@ </programlisting> </example> Think about <literal>global $var;</literal> as a shortcut to <literal>$var - =&amp; $GLOBALS['var'];</literal>. Thus assigning other reference + =&amp; $GLOBALS['var'];</literal>. Thus assigning another reference to <literal>$var</literal> only changes the local variable's reference. </para> </warning> @@ -170,8 +170,8 @@ </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: + by reference. This is done by making a local variable in a function and + a variable in the calling scope referencing the same content. Example: <informalexample> <programlisting role="php"> <![CDATA[ @@ -190,11 +190,11 @@ 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>. + <varname>$a</varname>. For more information on this, read the <link + linkend="language.references.pass">passing by reference</link> section. </para> <simpara> - The third thing reference can do is <link + The third thing references can do is <link linkend="language.references.return">return by reference</link>. </simpara> </sect1> @@ -202,7 +202,7 @@ <sect1 xml:id="language.references.arent"> <title>What References Are Not</title> <para> - As said before, references aren't pointers. That means, the + As said before, references are not pointers. That means, the following construct won't do what you expect: <informalexample> <programlisting role="php"> @@ -221,7 +221,7 @@ <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 + <varname>$bar</varname> in the caller, but then 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 @@ -237,8 +237,8 @@ <sect1 xml:id="language.references.pass"> <title>Passing by Reference</title> <para> - You can pass variable to function by reference, so that function could modify - its arguments. The syntax is as follows: + You can pass a variable by reference to a function so the function + can modify the variable. The syntax is as follows: <informalexample> <programlisting role="php"> <![CDATA[ @@ -255,28 +255,28 @@ ]]> </programlisting> </informalexample> - Note that there's no reference sign on function call - only on - function definition. Function definition alone is enough to + Note that there's no reference sign on a function call - only on + function definitions. Function definitions alone are enough to correctly pass the argument by reference. In recent versions of PHP - you will get a warning saying that "Call-time pass-by-reference" is - deprecated when you use a &amp; in <literal>foo(&amp;$a);</literal>. + you will get a warning saying that "call-time pass-by-reference" is + deprecated when you use &amp; in <literal>foo(&amp;$a);</literal>. </para> <para> The following things can be passed by reference: <itemizedlist> <listitem> <simpara> - Variable, i.e. <literal>foo($a)</literal> + Variables, i.e. <literal>foo($a)</literal> </simpara> </listitem> <listitem> <simpara> - New statement, i.e. <literal>foo(new foobar())</literal> + New statements, i.e. <literal>foo(new foobar())</literal> </simpara> </listitem> <listitem> <para> - Reference, returned from a function, i.e.: + References returned from functions, i.e.: <informalexample> <programlisting role="php"> <![CDATA[ @@ -291,14 +291,14 @@ ]]> </programlisting> </informalexample> - See also explanations about <link + See more about <link linkend="language.references.return">returning by reference</link>. </para> </listitem> </itemizedlist> </para> <para> - Any other expression should not be passed by reference, as the + No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid: <informalexample> @@ -325,11 +325,11 @@ <sect1 xml:id="language.references.return"> <title>Returning References</title> <para> - Returning by-reference is useful when you want to use a function - to find which variable a reference should be bound to. Do - <emphasis>not</emphasis> use return-by-reference to increase performance, the - engine is smart enough to optimize this on its own. Only return references - when you have a valid technical reason to do it! To + Returning by reference is useful when you want to use a function + to find to which variable a reference should be bound. Do + <emphasis>not</emphasis> use return-by-reference to increase performance. + The engine will automatically optimize this on its own. Only return + references when you have a valid technical reason to do so. To return references, use this syntax: <informalexample> <programlisting role="php"> @@ -359,7 +359,7 @@ <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 + want to return by reference, not a copy, and to indicate that reference binding, rather than usual assignment, should be done for <varname>$myValue</varname>. </simpara> @@ -371,9 +371,9 @@ work as you are attempting to return the result of an <emphasis>expression</emphasis>, and not a variable, by reference. You can only return variables by reference from a function - nothing else. - <constant>E_NOTICE</constant> error is issued since PHP 4.4.0 and PHP - 5.1.0 if the code tries to return a dynamic expression or a result of the - <literal>new</literal> operator. + Since PHP 4.4.0 in the PHP4 branch, and PHP 5.1.0 in the PHP5 branch, an + <constant>E_NOTICE</constant> error is issued if the code tries to return + a dynamic expression or a result of the <literal>new</literal> operator. </simpara> </note> </sect1> @@ -398,7 +398,7 @@ won't unset <varname>$b</varname>, just <varname>$a</varname>. </para> <simpara> - Again, it might be useful to think about this as analogous to Unix + Again, it might be useful to think about this as analogous to the Unix <command>unlink</command> call. </simpara> </sect1> @@ -407,16 +407,16 @@ <title>Spotting References</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 + mechanisms, so everything mentioned herein about reference binding also + applies to these constructs. Some constructs, like passing and + returning by reference, are mentioned above. Other constructs that use references are: </simpara> <sect2 xml:id="references.global"> <title><literal>global</literal> References</title> <para> - When you declare variable as <command>global $var</command> you + When you declare a variable as <command>global $var</command> you are in fact creating reference to a global variable. That means, this is the same as: <informalexample> @@ -430,8 +430,8 @@ </informalexample> </para> <simpara> - That means, for example, that unsetting <varname>$var</varname> - won't unset global variable. + This also means that unsetting <varname>$var</varname> + won't unset the global variable. </simpara> </sect2>
« previous php.doc.cvs (#2865) next »