PHP 8.3.4 Released!

is_object

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

is_objectPrüft, ob eine Variable vom Typ object ist

Beschreibung

is_object(mixed $value): bool

Prüft, ob die gegebene Variable ein Objekt ist.

Parameter-Liste

value

Die zu untersuchende Variable.

Rückgabewerte

Gibt true zurück, wenn value vom Typ object ist, ansonsten false.

Changelog

Version Beschreibung
7.2.0 is_object() liefert nun true für unserialisierte Objekte ohne Klassendefinition (Klasse __PHP_Incomplete_Class) zurück. Zuvor wurde false zurückgeliefert.

Beispiele

Beispiel #1 is_object()-Beispiel

<?php
// Eine einfache Funktion deklarieren, die ein Array unseres Objekts zurückgibt
function get_students($obj)
{
if (!
is_object($obj)) {
return
false;
}

return
$obj->students;
}

// Deklarieren einer neuen Instanz der Klasse und Befüllen mit Werten
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');

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

Siehe auch

  • is_bool() - Prüft, ob eine Variable vom Typ boolean ist
  • is_int() - Prüft, ob eine Variable vom Typ int ist
  • is_float() - Prüft, ob eine Variable vom Typ float ist
  • is_string() - Prüft, ob Variable vom Typ string ist
  • is_array() - Prüft, ob die Variable ein Array ist

add a note

User Contributed Notes 2 notes

up
94
peter dot nagel at portavita dot nl
12 years ago
Note: is_object(null) returns false

This should actually be part of the input/output specification at the top of this page.
up
5
mark at not4you dot com
12 years ago
Unserializes data as returned by the standard PHP serialize() function. If the unserialized object is not an array, it will be converted to one, particularily useful if it returns a __PHP_Incomplete_Class.

<?php
/**
*
* @param string $data Serialized data
*
* @return array Unserialized array
*/
function unserialize2array($data) {
$obj = unserialize($data);
if(
is_array($obj)) return $obj;
$arr = array();
foreach(
$obj as $k=>$v) {
$arr[$k] = $v;
}
unset(
$arr['__PHP_Incomplete_Class_Name']);
return
$arr;
}
?>
To Top