PHP Doku:: Dynamically changes the code of the given method - function.classkit-method-redefine.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenClasskitClasskit Funktionenclasskit_method_redefine

Ein Service von Reinhard Neidl - Webprogrammierung.

Classkit Funktionen

<<classkit_method_copy

classkit_method_remove>>

classkit_method_redefine

(PECL classkit >= 0.1)

classkit_method_redefineDynamically changes the code of the given method

Beschreibung

bool classkit_method_redefine ( string $classname , string $methodname , string $args , string $code [, int $flags = CLASSKIT_ACC_PUBLIC ] )

Hinweis: Diese Funktion kann nicht genutzt werden, um die aktuell ausgeführte (oder verkette) Methode zu manipulieren.

Warnung

Diese Funktion ist EXPERIMENTELL. Das Verhalten, der Funktionsname und alles Andere, was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohne Ankündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion auf eigenes Risiko.

Parameter-Liste

classname

The class in which to redefine the method

methodname

The name of the method to redefine

args

Comma-delimited list of arguments for the redefined method

code

The new code to be evaluated when methodname is called

flags

The redefined method can be CLASSKIT_ACC_PUBLIC, CLASSKIT_ACC_PROTECTED or CLASSKIT_ACC_PRIVATE

Hinweis:

This parameter is only used as of PHP 5, because, prior to this, all methods were public.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 classkit_method_redefine() example

<?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
classkit_method_redefine(
    
'Example',
    
'foo',
    
'',
    
'return "bar!\n";',
    
CLASSKIT_ACC_PUBLIC
);

// output Example::foo() (after redefine)
echo "After: " $e->foo();
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Before: foo!
After: bar!

Siehe auch


Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)