Define a human
Class person{public $name;p ublic $gender;p ublic function Say () {//echo $this->name. Say ". $this->gender;} Public Function __set ($name, $value) {$this->name= $value;} Public Function __get ($name) {if (!isset ($name)) {echo "not set";} Else{return $this $name;}}} $student =new person (), $student->name= "Cat", $student->gender= "male"; $student->say (); $student->age = " 12 ";
Get the class name in PHP by reflection, method name
Use the class function Var_dump (Get_object_vars ($student)); Returns an associative array of objects var_dump (Get_class_vars (Get_class ($student)));//properties of the Class Var_dump (Get_class_methods (Get_class ($student)) );//array of method names echo Get_class ($student);//class name
Use reflection Api$reflect = new Reflectionobject ($student), $props = $reflect->getproperties (); foreach ($props as $prop) { Print $prop->getname (). "
";} Returns all methods of an object $m = $reflect->getmethods (), foreach ($m as $prop) {print $prop->getname ();} Var_dump ($props);