Home  >  Article  >  php教程  >  PHP取得一个类的属性和方法的实现代码

PHP取得一个类的属性和方法的实现代码

WBOY
WBOYOriginal
2016-06-13 12:09:031097browse

复制代码 代码如下:


class myclass {
var $var1;
var $var2 = 'xyz';
var $var3 = 100;
private $var4;
function myclass() {
$this->val1 = "foo";
$this->val2 = "bar";
return true;
}

function test1() {
return true;
}
}

//get_class_methods() 返回由类的方法名组成的数组
get_class_methods('myclass') 或 get_class_methods(new myclass()) ;

//get_class() 返回对象的类名
//get_class_vars() 返回由类的默认属性组成的数组
$my_class = new myclass();
$class_vals = get_class_vars(get_class($my_class));
foreach($class_vars as $name => $value) {
echo "$name : $value\n
";
}
?>

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