PHP | is_object() Function
Last Updated :
27 Apr, 2020
Improve
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:
php
Output:
php
Output:
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.
<?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";
}
?>
ObjectProgram 2:
<?php
// Create a class
class GFG {
public $Geek_name =
"Welcome to GeeksforGeeks";
}
// Create the class name alias
class_alias('GFG', 'GeeksforGeeks');
$obj1 = new GFG();
$obj2 = new GeeksforGeeks();
$obj3 = 'GeeksforGeeks';
var_dump(is_object($obj1));
var_dump(is_object($obj2));
var_dump(is_object($obj3));
?>
bool(true) bool(true) bool(false)Reference: https://www.php.net/manual/en/function.is-object.php