PHP8 runkit7_method_copy — 將一個(gè)方法從一個(gè)類復(fù)制到另一個(gè)類中

2023-10-07 10:52 更新

(PECL runkit7 >= Unknown)

runkit7_method_copy — 將一個(gè)方法從一個(gè)類復(fù)制到另一個(gè)類中

說明

runkit7_method_copy(
    string $destination_class,
    string $destination_method_name,
    string $source_class,
    string $source_method_name = ?
): bool

參數(shù)

destination_class

復(fù)制方法的目標(biāo)類。

destination_method_name

目標(biāo)方法的名稱。

source_class

要復(fù)制的方法的源類。

source_method_name

從源類復(fù)制的方法的名稱。如果省略此參數(shù),將使用 ?destination_method_name? 的值。

返回值

示例

示例 #1 runkit7_method_copy() example

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

class Bar {
// initially, no methods
}

// copy the example() method from the Foo class to the Bar class, as baz()
runkit7_method_copy('Bar', 'baz', 'Foo', 'example');

// output copied function
echo Bar::baz();
?>

以上示例會(huì)輸出:

foo!

參見

  • runkit7_method_add() - 動(dòng)態(tài)地向給定類添加新方法 
  • runkit7_method_redefine() - 動(dòng)態(tài)地更改給定方法的代碼 
  • runkit7_method_remove() - 動(dòng)態(tài)地移除給定方法 
  • runkit7_method_rename() - 動(dòng)態(tài)地更改給定方法的名稱 
  • runkit7_function_copy() - 復(fù)制一個(gè)函數(shù)到一個(gè)新的函數(shù)名


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)