mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Anonymous functions
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@277637 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b97cfb3067
commit
19a7b598e9
3 changed files with 66 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.81 $ -->
|
||||
<!-- $Revision: 1.82 $ -->
|
||||
|
||||
<appendix xml:id="reserved" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>List of Reserved Words</title>
|
||||
|
@ -337,7 +337,7 @@
|
|||
|
||||
<simpara>
|
||||
These additional predefined classes were introduced in
|
||||
PHP 5.0.0
|
||||
PHP 5.0.0.
|
||||
</simpara>
|
||||
|
||||
<variablelist>
|
||||
|
@ -358,6 +358,24 @@
|
|||
</variablelist>
|
||||
</sect2>
|
||||
|
||||
<sect2 xml:id="reserved.classes.closure">
|
||||
<title>Closure</title>
|
||||
|
||||
<simpara>
|
||||
The predefined final class <classname>Closure</classname> was introduced
|
||||
in PHP 5.3.0. It is used for internal implementation of <link
|
||||
linkend="functions.anonymous">anonymous functions</link>.
|
||||
</simpara>
|
||||
<simpara>
|
||||
The class has a constructor forbiding the manual creation of the object
|
||||
(issues <constant>E_RECOVERABLE_ERROR</constant>) and the
|
||||
<literal>__invoke</literal> method with the <link
|
||||
linkend="language.oop5.magic.invoke">calling magic</link>.
|
||||
</simpara>
|
||||
|
||||
</sect2>
|
||||
|
||||
|
||||
<sect2 xml:id="reserved.classes.special">
|
||||
<title>Special classes</title>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.69 $ -->
|
||||
<!-- $Revision: 1.70 $ -->
|
||||
<chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
|
||||
<title>Functions</title>
|
||||
|
||||
|
@ -603,6 +603,41 @@ $foo->$funcname(); // This calls $foo->Variable()
|
|||
<function>dl</function>.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 xml:id="functions.anonymous">
|
||||
<title>Anonymous functions</title>
|
||||
<para>
|
||||
Anonymous functions allow creation of functions without specifying their
|
||||
name. They are most useful in <link
|
||||
linkend="language.types.callback">callback</link> parameters but the usage
|
||||
is not limited to that.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Anonymous function example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
echo preg_replace_callback('~-([a-z])~', function ($match) {
|
||||
return strtoupper($match[1]);
|
||||
}, 'hello-world');
|
||||
// outputs helloWorld
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
Anonymous functions are internally implemented by the
|
||||
<link linkend="reserved.classes.closure"><literal>Closure</literal>
|
||||
class</link>.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Anonymous functions are available since PHP 5.3.0.
|
||||
</para>
|
||||
</note>
|
||||
</sect1>
|
||||
|
||||
</chapter>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<refentry xml:id="function.create-function" xmlns="http://docbook.org/ns/docbook">
|
||||
<refnamediv>
|
||||
<refname>create_function</refname>
|
||||
|
@ -229,6 +229,15 @@ Array
|
|||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<para>
|
||||
<simplelist>
|
||||
<member><link linkend="functions.anonymous">Anonymous functions</link></member>
|
||||
</simplelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
Loading…
Reference in a new issue