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

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怎么获取当前方法的参数值

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容