php-doc-en/language/predefined/closure/bind.xml
Gustavo André dos Santos Lopes efe3572eca Documenting closure methods. Note I put the closures under
language/predefined/interfaces.xml, this will have to be
moved to a more appropriate location.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@318236 c90b9560-bf6c-de11-be94-00142212c4b1
2011-10-19 22:32:47 +00:00

134 lines
3.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="closure.bind" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Closure::bind</refname>
<refpurpose>
Duplicates a closure with a specific bound object and class scope
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>Closure</type><methodname>Closure::bind</methodname>
<methodparam><type>Closure</type><parameter>closure</parameter></methodparam>
<methodparam><type>object</type><parameter>newthis</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>newscope</parameter>
<initializer>'static'</initializer></methodparam>
</methodsynopsis>
<para>
This method is a static version of <methodname>Closure::bindTo</methodname>.
See the documentation of that method for more information.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>closure</parameter></term>
<listitem>
<para>
The anonymous functions to bind.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>newthis</parameter></term>
<listitem>
<para>
The object to which the given anonymous function should be bound, or
&null; for the closure to be unbound.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>newscope</parameter></term>
<listitem>
<para>
The class scope to which associate the closure is to be associated, or
'static' to keep the current one. If an object is given, the type of the
object will be used instead. This determines the visibility of protected
and private methods of the bound object.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a new <classname>Closure</classname> object &return.falseforfailure;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>Closure::bind</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
class A {
private static $sfoo = 1;
private $ifoo = 2;
}
$cl1 = static function() {
return A::$sfoo;
};
$cl2 = function() {
return $this->ifoo;
};
$bcl1 = Closure::bind($cl1, null, 'A');
$bcl2 = Closure::bind($cl2, new A(), 'A');
echo $bcl1(), "\n";
echo $bcl2(), "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
1
2
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><link linkend="functions.anonymous">Anonymous functions</link></member>
<member><methodname>Closure::bindTo</methodname></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->