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

From: Date: Sun, 22 May 2016 19:45:38 +0000
Subject: svn: /phpdoc/en/trunk/language/ functions.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-14143@lists.php.net to get a copy of this message
tpunt Sun, 22 May 2016 19:45:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=339215 Log: Resolve doc bug #71348 Bug: https://bugs.php.net/71348 (Assigned) Static anonymous functions are not documented Changed paths: U phpdoc/en/trunk/language/functions.xml Modified: phpdoc/en/trunk/language/functions.xml =================================================================== --- phpdoc/en/trunk/language/functions.xml 2016-05-22 17:25:38 UTC (rev 339214) +++ phpdoc/en/trunk/language/functions.xml 2016-05-22 19:45:38 UTC (rev 339215) @@ -1325,6 +1325,10 @@ the value of <link linkend="language.types.callback">callback</link> parameters, but they have many other uses. </simpara> + <simpara> + Anonymous functions are implemented using the <link linkend="class.closure"> + <classname>Closure</classname></link> class. + </simpara> <example> <title>Anonymous function example</title> @@ -1498,12 +1502,65 @@ ]]> </programlisting> </example> + + <sect2> + <title>Static anonymous functions</title> + <para> + As of PHP 5.4, anonymous functions may be declared statically. This + prevents them from having the current class automatically bound to + them. Objects may also not be bound to them at runtime. + </para> + <para> + <example> + <title>Attempting to use <literal>$this</literal> inside a static anonymous function</title> + <programlisting role="php"> +<![CDATA[ +<?php + +new class { + function __construct() + { + (static function() { + var_dump($this); + })(); + } +}; +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +Notice: Undefined variable: this in %s on line %d +NULL +]]> + </screen> + </example> + </para> + + <para> + <example> + <title>Attempting to bind an object to a static anonymous function</title> + <programlisting role="php"> +<![CDATA[ +<?php + +(static function() { + // function body +})->call(new StdClass); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +Warning: Cannot bind an instance to a static closure in /in/sLLS9 on line 5 +]]> + </screen> + </example> + </para> + </sect2> - <simpara> - Anonymous functions are implemented using the <link linkend="class.closure"> - <classname>Closure</classname></link> class. - </simpara> - <sect2 role="changelog"> &reftitle.changelog; <para> @@ -1519,7 +1576,8 @@ <row> <entry>5.4.0</entry> <entry> - <varname>$this</varname> can be used in anonymous functions. + Anonymous functions may use <varname>$this</varname>, as well as be + declared statically. </entry> </row> <row>

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