HomeLanguagesPHP | is_object() Function

PHP | is_object() Function

The is_object() function is an inbuilt function in PHP which is used to check whether the given value is an object or not.

Syntax:

bool is_object( mixed $var )

Parameters: This function accepts single parameter as mentioned above and described below:

  • $var: It contains the value of variable that need to be check.

Return Value: It returns TRUE if the value of variable is an object, FALSE otherwise.

Program 1:




<?php
  
// Create a class
class GFG {
   
    public $data1; 
    public $data2; 
    public $data3; 
}
   
// Create an object
$obj = new GFG();
  
// Check the value of variable
// is an object or not
if(is_object($obj)) {
    echo "Object";
}
else {
    echo "Not Object";
}
?>


Output:

Object

Program 2:




<?php
  
// Create a class
class GFG {
    public $Geek_name = 
          "Welcome to neveropen"; 
} 
   
// Create the class name alias
class_alias('GFG', 'neveropen');
  
$obj1 = new GFG();
$obj2 = new neveropen();
$obj3 = 'neveropen';
  
var_dump(is_object($obj1));
var_dump(is_object($obj2));
var_dump(is_object($obj3));
  
?>


Output:

bool(true) 
bool(true) 
bool(false) 

Reference: https://www.php.net/manual/en/function.is-object.php

RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS