Isset Method

 <?php

//To check Whether any value is set OR Not to any Variable We can use isset() method.
//isset() function returns two values 1(True) OR 0(False).

class Student
{
    public $course;
    private $first_name;
    private $last_name;
    private $detail = ["name" => "Test name", "age" => "30"];

    public function setName($fname, $lname)
    {
        $this->first_name = $fname;
        $this->last_name = $lname;
    }
        // public function __isset($property)
        // {
        //     echo isset($this->$property);
        // }
    public function __isset($name)
    {
        echo isset($this->detail[$name]);
    }
}
$test = new Student();
$test->setName("Yahoo","Baba");

$test->course = "PHP";
echo isset($test->course);
echo "<br>";
echo isset($test->name);
// echo "<br>";
// echo isset($test->detail["name"]);

//  OUTPUT:
//`1
// 1

?>

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions