reference/runkit7/functions/runkit7-method-add.xml
917c06eac884740ef9285f59387a3f5259d66722
...
...
@@ -0,0 +1,199 @@
1
+
<?xml version="1.0" encoding="utf-8"?>
2
+
<!-- $Revision$ -->
3
+

4
+
<refentry xml:id="function.runkit7-method-add" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
+
<refnamediv>
6
+
<refname>runkit7_method_add</refname>
7
+
<refpurpose>Dynamically adds a new method to a given class</refpurpose>
8
+
</refnamediv>
9
+

10
+
<refsect1 role="description">
11
+
&reftitle.description;
12
+
<methodsynopsis>
13
+
<type>bool</type><methodname>runkit7_method_add</methodname>
14
+
<methodparam><type>string</type><parameter>class_name</parameter></methodparam>
15
+
<methodparam><type>string</type><parameter>method_name</parameter></methodparam>
16
+
<methodparam><type>string</type><parameter>argument_list</parameter></methodparam>
17
+
<methodparam><type>string</type><parameter>code</parameter></methodparam>
18
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>RUNKIT7_ACC_PUBLIC</initializer></methodparam>
19
+
<methodparam choice="opt"><type>string</type><parameter>doc_comment</parameter><initializer>&null;</initializer></methodparam>
20
+
<methodparam choice="opt"><type>string</type><parameter>return_type</parameter></methodparam>
21
+
<methodparam choice="opt"><type>bool</type><parameter>is_strict</parameter></methodparam>
22
+
</methodsynopsis>
23
+
<methodsynopsis>
24
+
<type>bool</type><methodname>runkit7_method_add</methodname>
25
+
<methodparam><type>string</type><parameter>class_name</parameter></methodparam>
26
+
<methodparam><type>string</type><parameter>method_name</parameter></methodparam>
27
+
<methodparam><type>Closure</type><parameter>closure</parameter></methodparam>
28
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>RUNKIT7_ACC_PUBLIC</initializer></methodparam>
29
+
<methodparam choice="opt"><type>string</type><parameter>doc_comment</parameter><initializer>&null;</initializer></methodparam>
30
+
<methodparam choice="opt"><type>string</type><parameter>return_type</parameter></methodparam>
31
+
<methodparam choice="opt"><type>bool</type><parameter>is_strict</parameter></methodparam>
32
+
</methodsynopsis>
33
+
</refsect1>
34
+
<refsect1 role="parameters">
35
+
&reftitle.parameters;
36
+
<variablelist>
37
+
<varlistentry>
38
+
<term><parameter>class_name</parameter></term>
39
+
<listitem>
40
+
<para>
41
+
The class to which this method will be added
42
+
</para>
43
+
</listitem>
44
+
</varlistentry>
45
+
<varlistentry>
46
+
<term><parameter>method_name</parameter></term>
47
+
<listitem>
48
+
<para>
49
+
The name of the method to add
50
+
</para>
51
+
</listitem>
52
+
</varlistentry>
53
+
<varlistentry>
54
+
<term><parameter>argument_list</parameter></term>
55
+
<listitem>
56
+
<para>
57
+
Comma-delimited list of arguments for the newly-created method
58
+
</para>
59
+
</listitem>
60
+
</varlistentry>
61
+
<varlistentry>
62
+
<term><parameter>code</parameter></term>
63
+
<listitem>
64
+
<para>
65
+
The code to be evaluated when <parameter>method_name</parameter>
66
+
is called
67
+
</para>
68
+
</listitem>
69
+
</varlistentry>
70
+
<varlistentry>
71
+
<term><parameter>closure</parameter></term>
72
+
<listitem>
73
+
<para>
74
+
A <classname>closure</classname> that defines the method.
75
+
</para>
76
+
</listitem>
77
+
</varlistentry>
78
+
<varlistentry>
79
+
<term><parameter>flags</parameter></term>
80
+
<listitem>
81
+
<para>
82
+
The type of method to create, can be
83
+
<constant>RUNKIT7_ACC_PUBLIC</constant>,
84
+
<constant>RUNKIT7_ACC_PROTECTED</constant> or
85
+
<constant>RUNKIT7_ACC_PRIVATE</constant> optionally combined via bitwise OR with
86
+
<constant>RUNKIT7_ACC_STATIC</constant>
87
+
</para>
88
+
</listitem>
89
+
</varlistentry>
90
+
<varlistentry>
91
+
<term><parameter>doc_comment</parameter></term>
92
+
<listitem>
93
+
<para>
94
+
The doc comment of the method.
95
+
</para>
96
+
</listitem>
97
+
</varlistentry>
98
+
<varlistentry>
99
+
<term><parameter>return_type</parameter></term>
100
+
<listitem>
101
+
<para>
102
+
The return type of the method.
103
+
104
+
</para>
105
+
</listitem>
106
+
</varlistentry>
107
+
<varlistentry>
108
+
<term><parameter>is_strict</parameter></term>
109
+
<listitem>
110
+
<para>
111
+
Whether the method behaves as if it were declared in a file with <literal>strict_types=1</literal>
112
+
</para>
113
+
</listitem>
114
+
</varlistentry>
115
+
</variablelist>
116
+
</refsect1>
117
+

118
+
<refsect1 role="returnvalues">
119
+
&reftitle.returnvalues;
120
+
<para>
121
+
&return.success;
122
+
</para>
123
+
</refsect1>
124
+

125
+

126
+
<refsect1 role="examples">
127
+
&reftitle.examples;
128
+
<para>
129
+
<example>
130
+
<title><function>runkit7_method_add</function> example</title>
131
+
<programlisting role="php">
132
+
<![CDATA[
133
+
<?php
134
+
class Example {
135
+
function foo() {
136
+
echo "foo!\n";
137
+
}
138
+
}
139
+

140
+
// create an Example object
141
+
$e = new Example();
142
+

143
+
// Add a new public method
144
+
runkit7_method_add(
145
+
'Example',
146
+
'add',
147
+
'$num1, $num2',
148
+
'return $num1 + $num2;',
149
+
RUNKIT7_ACC_PUBLIC
150
+
);
151
+

152
+
// add 12 + 4
153
+
echo $e->add(12, 4);
154
+
?>
155
+
]]>
156
+
</programlisting>
157
+
&example.outputs;
158
+
<screen>
159
+
<![CDATA[
160
+
16
161
+
]]>
162
+
</screen>
163
+
</example>
164
+
</para>
165
+
</refsect1>
166
+
<refsect1 role="seealso">
167
+
&reftitle.seealso;
168
+
<para>
169
+
<simplelist>
170
+
<member><function>runkit7_method_copy</function></member>
171
+
<member><function>runkit7_method_redefine</function></member>
172
+
<member><function>runkit7_method_remove</function></member>
173
+
<member><function>runkit7_method_rename</function></member>
174
+
<member><function>runkit7_function_add</function></member>
175
+
</simplelist>
176
+
</para>
177
+
</refsect1>
178
+
</refentry>
179
+

180
+
<!-- Keep this comment at the end of the file
181
+
Local variables:
182
+
mode: sgml
183
+
sgml-omittag:t
184
+
sgml-shorttag:t
185
+
sgml-minimize-attributes:nil
186
+
sgml-always-quote-attributes:t
187
+
sgml-indent-step:1
188
+
sgml-indent-data:t
189
+
indent-tabs-mode:nil
190
+
sgml-parent-document:nil
191
+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
192
+
sgml-exposed-tags:nil
193
+
sgml-local-catalogs:nil
194
+
sgml-local-ecat-files:nil
195
+
End:
196
+
vim600: syn=xml fen fdm=syntax fdl=2 si
197
+
vim: et tw=78 syn=sgml
198
+
vi: ts=1 sw=1
199
+
-->
0
200