mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added a note about private and protected methods to callables
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@338094 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
83ea6bb48a
commit
db8f74138c
1 changed files with 11 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
|||
<!-- $Revision$ -->
|
||||
<sect1 xml:id="language.types.callable">
|
||||
<title>Callbacks / Callables</title>
|
||||
|
||||
|
||||
<para>
|
||||
Callbacks can be denoted by <type>callable</type> type hint as of PHP 5.4.
|
||||
This documentation used <type>callback</type> type information for the same
|
||||
|
@ -23,8 +23,8 @@
|
|||
A PHP function is passed by its name as a <type>string</type>. Any built-in
|
||||
or user-defined function can be used, except language constructs such as:
|
||||
<function>array</function>, <function>echo</function>,
|
||||
<function>empty</function>, <function>eval</function>,
|
||||
<function>exit</function>, <function>isset</function>,
|
||||
<function>empty</function>, <function>eval</function>,
|
||||
<function>exit</function>, <function>isset</function>,
|
||||
<function>list</function>, <function>print</function> or
|
||||
<function>unset</function>.
|
||||
</para>
|
||||
|
@ -32,7 +32,8 @@
|
|||
<para>
|
||||
A method of an instantiated <type>object</type> is passed as an
|
||||
<type>array</type> containing an <type>object</type> at index 0 and the
|
||||
method name at index 1.
|
||||
method name at index 1. Accessing protected and private methods from
|
||||
within a class is allowed.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -56,7 +57,7 @@
|
|||
</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
<?php
|
||||
|
||||
// An example callback function
|
||||
function my_callback_function() {
|
||||
|
@ -71,10 +72,10 @@ class MyClass {
|
|||
}
|
||||
|
||||
// Type 1: Simple callback
|
||||
call_user_func('my_callback_function');
|
||||
call_user_func('my_callback_function');
|
||||
|
||||
// Type 2: Static class method call
|
||||
call_user_func(array('MyClass', 'myCallbackMethod'));
|
||||
call_user_func(array('MyClass', 'myCallbackMethod'));
|
||||
|
||||
// Type 3: Object method call
|
||||
$obj = new MyClass();
|
||||
|
@ -128,8 +129,8 @@ $double = function($a) {
|
|||
// This is our range of numbers
|
||||
$numbers = range(1, 5);
|
||||
|
||||
// Use the closure as a callback here to
|
||||
// double the size of each element in our
|
||||
// Use the closure as a callback here to
|
||||
// double the size of each element in our
|
||||
// range
|
||||
$new_numbers = array_map($double, $numbers);
|
||||
|
||||
|
@ -159,7 +160,7 @@ print implode(' ', $new_numbers);
|
|||
</sect2>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
|
|
Loading…
Reference in a new issue