Home > Backend Development > PHP Tutorial > PHP obtains the implementation code of attributes and methods of a class_PHP tutorial

PHP obtains the implementation code of attributes and methods of a class_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:28:59
Original
932 people have browsed it

Copy code The code is as follows:

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() returns an array consisting of class method names
get_class_methods('myclass') or get_class_methods(new myclass());

//get_class() returns the class name of the object
//get_class_vars() returns an array consisting of the default attributes of the class
$my_class = new myclass();
$class_vals = get_class_vars(get_class($my_class));
foreach($class_vars as $ name => $value) {
echo "$name : $valuen
";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323502.htmlTechArticleCopy the code as follows: ?php class myclass { var $var1; var $var2 = 'xyz'; var $ var3 = 100; private $var4; function myclass() { $this-val1 = "foo"; $this-val2 = "bar"; return tr...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template