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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:09:03
Original
1147 people have browsed it

复制代码 代码如下:


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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template