PHP 8.3.4 Released!

is_object

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

is_objectDétermine si une variable est de type objet

Description

is_object(mixed $value): bool

Détermine si la variable donnée est de type objet.

Liste de paramètres

value

La variable à évaluer.

Valeurs de retour

Retourne true si value est un objet, false sinon.

Historique

Version Description
7.2.0 is_object() retourne maintenant true pour un objet désérialise sans une définition de classe (classe de __PHP_Incomplete_Class). Précédement false était retourné.

Exemples

Exemple #1 Exemple avec is_object()

<?php
// Déclare une simple fonction pour retourner un tableau
// de notre objet
function get_students($obj)
{
if (!
is_object($obj)) {
return
false;
}

return
$obj->students;
}

// Déclare une nouvelle instance et
// la remplit
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');

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

Voir aussi

  • is_bool() - Détermine si une variable est un booléen
  • is_int() - Détermine si une variable est de type nombre entier
  • is_float() - Détermine si une variable est de type nombre décimal
  • is_string() - Détermine si une variable est de type chaîne de caractères
  • is_array() - Détermine si une variable est un tableau

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