PHP gets the implementation code for a class's properties and methods
2020-05-07 19:17:38
OfStack
<?php
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 of 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 an array of the default properties of the class
$my_class = new myclass();
$class_vals = get_class_vars(get_class($my_class));
foreach($class_vars as $name => $value) {
echo "$name : $value\n<br/>";
}
?>