Write a PHP script to demonstrate the introspection for examining class .(use function get_declared_classes() ,get_class_methods() and get_class_vars())||EasyCoding45
In this Tutorial, we are going to learn how we can Write a PHP script to demonstrate the introspection for examining class .so we are going to use functions like get_declared_classes() ,get_class_methods() and get_class_vars() for the Above Question.
Program::--
<?php
class cylinder
{
const pi=3.14;
public $ar=null;
public $vol=null;
function area($r,$h)
{
$this->ar=2*self::pi*$r*$h+2*self::pi*$r*$r;
echo "Area of Cylinder is :$this->ar<br> ";
}
function volume($r,$h)
{
$this->vol=2*self::pi*$r*$r;
echo "\nVolume of Cylinder is :$this->vol";
}
}
/*$obj=new cylinder();
$obj->area(25,14);
$obj->volume(25,14);
*/
echo "<br>Classes are :";
$classes=get_declared_classes();
print_r($classes);
echo "<br>Class methods are :<br>";
$methods=get_class_methods(cylinder);
print_r($methods);
echo "<br>Class variables are :<br>";
$var=get_class_vars(cylinder);
print_r($var);
?>
Note ::--
We are Using Print_r() method so we can print returned Array.
Output::--
Thank You💚
Comments
Post a Comment