val2 = "bar"; return"/> val2 = "bar"; return">

Home  >  Article  >  Backend Development  >  pretty rhythm dear my future PHP obtains the implementation code of the attributes and methods of a class

pretty rhythm dear my future PHP obtains the implementation code of the attributes and methods of a class

WBOY
WBOYOriginal
2016-07-29 08:45:131081browse

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 the method names of the class
get_class_methods('myclass') or get_class_methods(new myclass());
//get_class() returns the class name of the object
//get_class_vars() returns the default value of the class Array of attributes
$my_class = new myclass();
$class_vals = get_class_vars(get_class($my_class));
foreach($class_vars as $name => $value) {
echo "$name : $valuen< br/>";
}
?>

The above introduces the implementation code of pretty rhythm dear my future PHP to obtain the attributes and methods of a class, including the content of pretty rhythm dear my future. I hope it will be helpful to friends who are interested in PHP tutorials.

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