PHP 8.5.0 Alpha 1 available for testing

is_object

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

is_objectDetermina si una variable es de tipo objeto

Descripción

is_object(mixed $value): bool

Determina si la variable dada es de tipo objeto.

Parámetros

value

La variable a evaluar.

Valores devueltos

Retorna true si value es un objet, false en caso contrario.

Historial de cambios

Versión Descripción
7.2.0 is_object() retorna ahora true para un objeto deserializado sin una definición de clase (clase de __PHP_Incomplete_Class). Anteriormente se retornaba false.

Ejemplos

Ejemplo #1 Ejemplo con is_object()

<?php
// Declara una función simple para retornar un array
// de nuestro objeto
function get_students($obj)
{
if (!
is_object($obj)) {
return
false;
}

return
$obj->students;
}

// Declara una nueva instancia y
// la rellena
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');

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

Ver también

  • is_bool() - Determina si una variable es un bool
  • is_int() - Determina si una variable es de tipo integer
  • is_float() - Determina si una variable es de tipo float
  • is_string() - Determina si una variable es de tipo string
  • is_array() - Determina si una variable es un array

add a note

User Contributed Notes 3 notes

up
99
peter dot nagel at portavita dot nl
14 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
4
mark at not4you dot com
13 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;
}
?>
up
1
monique at nijboer dot it
9 months 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