PHP Doku:: Copy a function to a new function name - function.runkit-function-copy.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenrunkitrunkit Funktionenrunkit_function_copy

Ein Service von Reinhard Neidl - Webprogrammierung.

runkit Funktionen

<<runkit_function_add

runkit_function_redefine>>

runkit_function_copy

(PECL runkit >= 0.7.0)

runkit_function_copy Copy a function to a new function name

Beschreibung

bool runkit_function_copy ( string $funcname , string $targetname )

Parameter-Liste

funcname

Name of existing function

targetname

Name of new function to copy definition to

Rückgabewerte

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

Beispiele

Beispiel #1 A runkit_function_copy() example

<?php
function original() {
  echo 
"In a function\n";
}
runkit_function_copy('original','duplicate');
original();
duplicate();
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

In a function
In a function

Siehe auch


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
radon8472 at radon-software dot net
7.12.2010 12:57
If you don`t have this function, yuo can use this:

<?php
 
// functions.inc.php : written by Radon8472 (2010-11-16) -- last modified: 2010-12-07

  // include guard
 
if( !defined("FUNCTIONS_INC_PHP") )
  {
   
define("FUNCTIONS_INC_PHP","1.0");

   
/**
      * Copy a function to a new function name
      *
      * @author: Radon8472
      * @version: 1.0 (2010-12-07)
      *
      * @param: string   $funcname        Name of existing function
      * @param: string   $targetname      Name of new function to copy definition to
      *
      * @return: Returns TRUE on success or FALSE on failure.
      * @todo: find a way to copy functions with refferece parameters
      */
   
function func_alias($funcname, $targetname)
    {
     
$ok = true;
      if( !
function_exists($funcname) ) $ok = false;
      if(
function_exists($targetname)) $ok = false;

      if(
$ok )
      {
       
$command = "function ".$targetname."() { ";
       
$command.= "\$args = func_get_args(); ";
       
$command.= "return call_user_func_array(\"".$funcname."\", \$args); }";

        @eval(
$command);
        if( !
function_exists($targetname) ) $ok = false;
      }
      return
$ok;
    }

   
func_alias("func_alias","function_copy");
    if(!
function_exists("runkit_function_copy"))
    {
     
func_alias("func_alias","runkit_function_copy");
    }
  }
?>



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",...)