svn: /phpdoc/en/trunk/language/ references.xml

From: Date: Thu, 09 Jun 2011 15:27:57 +0000
Subject: svn: /phpdoc/en/trunk/language/ references.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-8236@lists.php.net to get a copy of this message
chx Thu, 09 Jun 2011 15:27:57 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=311977 Log: Documented more the use of returned references. Changed paths: U phpdoc/en/trunk/language/references.xml Modified: phpdoc/en/trunk/language/references.xml =================================================================== --- phpdoc/en/trunk/language/references.xml 2011-06-09 14:10:38 UTC (rev 311976) +++ phpdoc/en/trunk/language/references.xml 2011-06-09 15:27:57 UTC (rev 311977) @@ -444,6 +444,42 @@ a dynamic expression or a result of the <literal>new</literal> operator. </simpara> </note> + To use the returned reference, you must use reference assigment: + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +function &collector() { + static $collection = array(); + return $collection; +} +$collection = &collector(); +$collection[] = 'foo'; +?> +]]> + </programlisting> + </informalexample> + To pass the returned reference to another function expecting a reference + you can use this syntax: + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +function &collector() { + static $collection = array(); + return $collection; +} +array_push(collector(), 'foo'); +?> +]]> + </programlisting> + </informalexample> + <note> + <simpara> + Note that <literal>array_push(&collector(), 'foo');</literal> will + <emphasis>not</emphasis> work, it results in a fatal error. + </simpara> + </note> </sect1> <sect1 xml:id="language.references.unset">

« previous php.doc.cvs (#8236) next »