PHP 8.5.0 Alpha 2 available for testing

runkit7_method_redefine

(PECL runkit7 >= Unknown)

runkit7_method_redefineCambiar dinámicamente el código del método dado

Descripción

runkit7_method_redefine(
    string $class_name,
    string $method_name,
    string $argument_list,
    string $code,
    int $flags = RUNKIT7_ACC_PUBLIC,
    string $doc_comment = null,
    string $return_type = ?,
    bool $is_strict = ?
): bool
runkit7_method_redefine(
    string $class_name,
    string $method_name,
    Closure $closure,
    int $flags = RUNKIT7_ACC_PUBLIC,
    string $doc_comment = null,
    string $return_type = ?,
    bool $is_strict = ?
): bool

Parámetros

class_name

La clase en la que redefinir el método

method_name

El nombre del método a redefinir

argument_list

La lista de argumentos separados por comas para el método redefinido

code

El nuevo código a evaluar cuando method_name es llamado

closure

Una closure que define el método.

flags

El método redefinido puede ser RUNKIT7_ACC_PUBLIC, RUNKIT7_ACC_PROTECTED o RUNKIT7_ACC_PRIVATE opcionalmente combinado mediante una operación bit a bit OU con RUNKIT7_ACC_STATIC

doc_comment

El comentario de documentación del método.

return_type

El tipo de retorno del método.

is_strict

Si el método se comporta como si fuera declarado en un archivo con strict_types=1

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo de runkit7_method_redefine()

<?php
class Example {
function
foo() {
return
"foo!\n";
}
}

// crear un objeto Example
$e = new Example();

// muestra Example::foo() (antes de la redefinición)
echo "Before: " . $e->foo();

// Redefine el método 'foo'
runkit7_method_redefine(
'Example',
'foo',
'',
'return "bar!\n";',
RUNKIT7_ACC_PUBLIC
);

// muestra Example::foo() (después de la redefinición)
echo "After: " . $e->foo();
?>

El ejemplo anterior mostrará :

Before: foo!
After: bar!

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top