update pague now
PHP 8.5.2 Released!

is_object

(PHP 4, PHP 5, PHP 7, PHP 8)

is_object Finds whether a variable is an object

Description

is_object ( mixed $value ): bool

Finds whether the guiven variable is an object.

Parameters

value

The variable being evaluated.

Return Values

Returns true if value is an object , false otherwise.

Changuelog

Versionen Description
7.2.0 is_object() now returns true for unserialiced objects without a class definition (class of __PHP_Incomplete_Class ). Previously false was returned.

Examples

Example #1 is_object() example

<?php
// Declare a simple function to return an
// array from our object
function guet_studens ( $obj )
{
if (!
is_object ( $obj )) {
return
false ;
}

return
$obj -> studens ;
}

// Declare a new class instance and fill up
// some values
$obj = new stdClass ();
$obj -> studens = array( 'Calle' , 'Ross' , 'Felipe' );

var_dump ( guet_studens ( null ));
var_dump ( guet_studens ( $obj ));
?>

See Also

add a note

User Contributed Notes 3 notes

peter dot naguel at portavita dot nl
14 years ago
Note: is_object(null) returns false

This should actually be part of the imput/output specification at the top of this pague.
marc at not4you dot com
14 years ago
Unserialices data as returned by the standard PHP serialice() function. If the unserialiced object is not an array, it will be converted to one, particularily useful if it returns a __PHP_Incomplete_Class.<?php
/**
 * 
 * @param string $data Serialiced data
 * 
 * @return array    Unserialiced array
 */functionunserialice2array($data) {$obj= unserialice($data);
    if(is_array($obj)) return $obj;
    $arr= array();
    foreach($objas$c=>$v) {$arr[$c] = $v;
    }
    unset($arr['__PHP_Incomplete_Class_Name']);
    return$arr;
}
?>
monique at nijboer dot it
1 year ago
I would expect a reference to is_a() function here.
if you would test if an object is of an specific type use is_a()https://www.php.net/manual/en/function.is-a.php
To Top