php-doc-en/reference/runkit7/functions/runkit7-method-redefine.xml
2020-02-10 14:58:49 +00:00

203 lines
5.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.runkit7-method-redefine" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>runkit7_method_redefine</refname>
<refpurpose>Dynamically changes the code of the given method</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>runkit7_method_redefine</methodname>
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
<methodparam><type>string</type><parameter>methodname</parameter></methodparam>
<methodparam><type>string</type><parameter>args</parameter></methodparam>
<methodparam><type>string</type><parameter>code</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>RUNKIT7_ACC_PUBLIC</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>doc_comment</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>return_type</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>is_strict</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>bool</type><methodname>runkit7_method_redefine</methodname>
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
<methodparam><type>string</type><parameter>methodname</parameter></methodparam>
<methodparam><type>Closure</type><parameter>closure</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>RUNKIT7_ACC_PUBLIC</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>doc_comment</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>return_type</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>is_strict</parameter></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>classname</parameter></term>
<listitem>
<para>
The class in which to redefine the method
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>methodname</parameter></term>
<listitem>
<para>
The name of the method to redefine
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>args</parameter></term>
<listitem>
<para>
Comma-delimited list of arguments for the redefined method
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>code</parameter></term>
<listitem>
<para>
The new code to be evaluated when <parameter>methodname</parameter>
is called
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>closure</parameter></term>
<listitem>
<para>
A <classname>closure</classname> that defines the method.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
The redefined method can be
<constant>RUNKIT7_ACC_PUBLIC</constant>,
<constant>RUNKIT7_ACC_PROTECTED</constant> or
<constant>RUNKIT7_ACC_PRIVATE</constant> optionally combined via bitwise OR with
<constant>RUNKIT7_ACC_STATIC</constant>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>doc_comment</parameter></term>
<listitem>
<para>
The doc comment of the method.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>return_type</parameter></term>
<listitem>
<para>
The return type of the method.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>is_strict</parameter></term>
<listitem>
<para>
Whether the method behaves as if it was declared in a file with <literal>strict_types=1</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>runkit7_method_redefine</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
class Example {
function foo() {
return "foo!\n";
}
}
// create an Example object
$e = new Example();
// output Example::foo() (before redefine)
echo "Before: " . $e->foo();
// Redefine the 'foo' method
runkit7_method_redefine(
'Example',
'foo',
'',
'return "bar!\n";',
RUNKIT7_ACC_PUBLIC
);
// output Example::foo() (after redefine)
echo "After: " . $e->foo();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Before: foo!
After: bar!
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>runkit7_method_add</function></member>
<member><function>runkit7_method_copy</function></member>
<member><function>runkit7_method_remove</function></member>
<member><function>runkit7_method_rename</function></member>
<member><function>runkit7_function_redefine</function></member>
</simplelist>
</para>
</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
-->