略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: runkit_function_copy

2024-12-21

runkit_function_copy

(PECL runkit >= 0.7.0)

runkit_function_copy Copy a function to a new function name

说明

runkit_function_copy ( string $funcname , string $targetname ) : bool

参数

funcname

Name of existing function

targetname

Name of new function to copy definition to

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 A runkit_function_copy() example

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

以上例程会输出:

In a function
In a function

参见

add a note add a note

User Contributed Notes 2 notes

up
0
radon8472 at radon-software dot net
8 years ago
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");
    }
  }
?>
up
-2
gruessle @ gmail dot com
8 years ago
(PHP 5 >= 5.3.0)
class_alias — Creates an alias for a class
http://php.net/manual/en/function.class-alias.php

For (PHP 5 < 5.3.0) you can use following:

<?php
if ( ! function_exists('class_alias')) {
    function
class_alias($original, $alias) {
        eval(
'abstract class ' . $alias . ' extends ' . $original . ' {}');
    }
}

class_alias('print_r', 'printr');
?>

官方地址:https://www.php.net/manual/en/function.runkit-function-copy.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3