svn: /phpdoc/en/trunk/ appendices/migration70/new-features.xml language/predefined/closure/call.xml language/predefined/versions.xml

From: Date: Sun, 09 Aug 2015 01:17:26 +0000
Subject: svn: /phpdoc/en/trunk/ appendices/migration70/new-features.xml language/predefined/closure/call.xml language/predefined/versions.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-13555@lists.php.net to get a copy of this message
aharvey Sun, 09 Aug 2015 01:17:26 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=337372 Log: Expand the Closure::call() documentation. Changed paths: U phpdoc/en/trunk/appendices/migration70/new-features.xml U phpdoc/en/trunk/language/predefined/closure/call.xml U phpdoc/en/trunk/language/predefined/versions.xml Modified: phpdoc/en/trunk/appendices/migration70/new-features.xml =================================================================== --- phpdoc/en/trunk/appendices/migration70/new-features.xml 2015-08-09 01:17:21 UTC (rev 337371) +++ phpdoc/en/trunk/appendices/migration70/new-features.xml 2015-08-09 01:17:26 UTC (rev 337372) @@ -287,20 +287,17 @@ </sect2> <sect2 xml:id="migration70.new-features.closure-call-method"> - <title>Closure::call() Method</title> + <title><methodname>Closure::call</methodname></title> <para> - The new <function>call</function> method for closures is used as a shorthand - way of invoking a closure whilst binding an object scope to it. This creates - more perfomant and compact code by removing the need to create an - intermediate closure before invoking it. + <methodname>Closure::call</methodname> is a more performant, shorthand way + of temporarily binding an object scope to a closure and invoking it. </para> <informalexample> <programlisting role="php"> <![CDATA[ <?php - class A {private $x = 1;} // Pre PHP 7 code Modified: phpdoc/en/trunk/language/predefined/closure/call.xml =================================================================== --- phpdoc/en/trunk/language/predefined/closure/call.xml 2015-08-09 01:17:21 UTC (rev 337371) +++ phpdoc/en/trunk/language/predefined/closure/call.xml 2015-08-09 01:17:26 UTC (rev 337372) @@ -4,34 +4,38 @@ <refentry xml:id="closure.call" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>Closure::call</refname> - <refpurpose>Calls the closure with the given parameters and returns the result, with $this bound to the given object $to</refpurpose> + <refpurpose>Binds and calls the closure</refpurpose> </refnamediv> <refsect1 role="description"><!-- {{{ --> &reftitle.description; <methodsynopsis> - <modifier>public</modifier> <type>Closure</type><methodname>Closure::call</methodname> - <methodparam><type>object</type><parameter>to</parameter></methodparam> - <methodparam choice="opt"><type>mixed</type><parameter>parameters</parameter></methodparam> + <modifier>public</modifier> <type>mixed</type><methodname>Closure::call</methodname> + <methodparam><type>object</type><parameter>newthis</parameter></methodparam> + <methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam> </methodsynopsis> <para> - Calls the closure with the given parameters and returns the result, with $this bound to the given object - <parameter>to</parameter> + Temporarily binds the closure to <parameter>newthis</parameter>, and calls + it with any given parameters. </para> </refsect1><!-- }}} --> <refsect1 role="parameters"><!-- {{{ --> &reftitle.parameters; <variablelist> <varlistentry> - <term><parameter>to</parameter></term> + <term><parameter>newthis</parameter></term> <listitem> <para> + The <type>object</type> to bind the closure to for the duration of the + call. </para> </listitem> </varlistentry> <varlistentry> - <term><parameter>parameters</parameter></term> + <term><parameter>...</parameter></term> <listitem> <para> + Zero or more parameters, which will be given as parameters to the + closure. </para> </listitem> </varlistentry> @@ -40,29 +44,9 @@ <refsect1 role="returnvalues"><!-- {{{ --> &reftitle.returnvalues; <para> + Returns the return value of the closure. </para> </refsect1><!-- }}} --> - <refsect1 role="changelog"><!-- {{{ --> - &reftitle.changelog; - <informaltable> - <tgroup cols="2"> - <thead> - <row> - <entry>&Version;</entry> - <entry>&Description;</entry> - </row> - </thead> - <tbody> - <row> - <entry>7.0.0</entry> - <entry> - Added Closure::call - </entry> - </row> - </tbody> - </tgroup> - </informaltable> - </refsect1><!-- }}} --> <refsect1 role="examples"> &reftitle.examples; <example> @@ -70,12 +54,34 @@ <programlisting role="php"> <![CDATA[ <?php -$foo = new StdClass; -$foo->bar = 3; -$foobar = function ($qux) { var_dump($this->bar + $qux); }; -$foobar->call($foo, 4); // prints int(7) +class Value { + protected $value; + + public function __construct($value) { + $this->value = $value; + } + + public function getValue() { + return $this->value; + } +} + +$three = new Value(3); +$four = new Value(4); + +$closure = function ($delta) { var_dump($this->getValue() + $delta); }; +$closure->call($three, 4); +$closure->call($four, 4); +?> ]]> </programlisting> + &example.outputs; + <screen> +<![CDATA[ +int(7) +int(8) +]]> + </screen> </example> </refsect1> </refentry> Modified: phpdoc/en/trunk/language/predefined/versions.xml =================================================================== --- phpdoc/en/trunk/language/predefined/versions.xml 2015-08-09 01:17:21 UTC (rev 337371) +++ phpdoc/en/trunk/language/predefined/versions.xml 2015-08-09 01:17:26 UTC (rev 337372) @@ -56,6 +56,7 @@ <function name='closure::__construct' from='PHP 5 &gt;= 5.3.0'/> <function name='closure::bind' from='PHP 5 &gt;= 5.4.0'/> <function name='closure::bindto' from='PHP 5 &gt;= 5.4.0'/> + <function name='closure::call' from='PHP 7'/> <function name='namespaces' from='PHP 5 &gt;= 5.3.0'/> <function name='generators' from='PHP 5 &gt;= 5.5.0'/>

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