Home >Backend Development >PHP Tutorial >请问用名称调用函数和传参

请问用名称调用函数和传参

WBOY
WBOYOriginal
2016-06-13 11:26:33775browse

请教用名称调用函数和传参
会用call_user_func_array调用已知名称的函数, 但调用已实例化的类就不会了...

<br />	class class_a<br />	{<br />		public $var_a	= 0;<br />		<br />		public function fun_1 ( $var )<br />		{<br />			var_dump( $this->var_a + $var );<br />		}<br />	};<br />	<br />	$obj_a	= new class_a();<br />	$obj_a->var_a	= 6;<br />	<br />	call_user_func_array( array( 'class_a', 'fun_1' ), array( 5 ) );<br />

这样会报两个错, 1个说是call_user_func_array调用了非静态方法, 2个是this不能出现在未实例化的类里
其实在call_user_func_array里出现这两个错误都很好理解...
那有其它方法可以实现 利用函数名调用已实例化的类的成员函数, 并且传不定个数的参数么...

call_user_func_array 传参
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:sqlsrv函数有关问题Next article:phpmyadmin访问回绝