php怎么获取当前方法的参数值

来自:互联网
时间:2021-10-18
阅读:

php获取当前方法的参数值

方法1:利用func_get_arg()函数

func_get_arg()函数可返回当前方法中指定位置的参数值

示例:

<?php
header("Content-type:text/html;charset=utf-8");
class Website {
	public function Write(){ 
		echo "第二个参数值为: " . func_get_arg(1) . "<br />\n";
	}

}
$object = new Website();
$object -> Write(1,2,3);
?>

输出结果:

php怎么获取当前方法的参数值

方法2:利用func_get_args()函数

func_get_args()可返回包含当前方法所有参数值的一个数组

示例:

<?php
header("Content-type:text/html;charset=utf-8");
class Website {
	public function Write(){
		$arg_list = func_get_args(); 
		var_dump($arg_list);
	}

}
$object = new Website();
$object -> Write(1,2,3);
?>

输出结果:

php怎么获取当前方法的参数值

返回顶部
顶部