📜  PHP |反射方法 export()函数

📅  最后修改于: 2022-05-13 01:56:45.958000             🧑  作者: Mango

PHP |反射方法 export()函数

ReflectionMethod::export()函数是PHP中的一个内置函数,如果 return 参数设置为 TRUE,则用于将导出作为字符串返回,否则返回 NULL。

句法:

string ReflectionMethod::export ( $class, $name, $return )

参数:此函数接受三个参数,如上所述,如下所述:

  • class:这是初始化类的名称。
  • name:这是方法的名称。
  • return:它的值是 TRUE 或 FALSE。使用 TRUE 将返回导出,而使用 FALSE 则相反。

返回值:如果返回参数已设置为 TRUE,则此函数将导出作为字符串返回,否则返回 NULL。

下面的程序说明了PHP中的ReflectionMethod::export()函数
程序_1:

export( 'Company', 'GeeksforGeeks', $return = TRUE );
  
// Getting the the export as a string if the 
// return parameter has been set to TRUE, 
// otherwise NULL is returned.
var_dump($B);
?>

输出:

string(171) "Method [  protected method GeeksforGeeks ] {
  @@ /home/cd1a603457d3beda20350155354b4363.php 6 - 8

  - Parameters [1] {
    Parameter #0 [  $name ]
  }
}
"

程序_2:

export( 'Department1', 'HR', $return = TRUE ));
var_dump($B->export( 'Department2', 'Coding', $return = FALSE ));
var_dump($C->export( 'Department3', 'Marketing', $return = FALSE ));
?>

输出:

string(160) "Method [  protected method HR ] {
  @@ /home/b1fa43e2f382f32d60abd4370db4a4f6.php 6 - 8

  - Parameters [1] {
    Parameter #0 [  $name ]
  }
}
"
Method [  protected method Coding ] {
  @@ /home/b1fa43e2f382f32d60abd4370db4a4f6.php 12 - 14

  - Parameters [1] {
    Parameter #0 [  $name ]
  }
}

NULL
Method [  protected method Marketing ] {
  @@ /home/b1fa43e2f382f32d60abd4370db4a4f6.php 18 - 20

  - Parameters [1] {
    Parameter #0 [  $name ]
  }
}

NULL

参考: https://www. PHP.net/manual/en/reflectionmethod.export。 PHP