PHP 8.3.4 Released!

is_object

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

is_objectVerifica se uma variável é um objeto

Descrição

is_object(mixed $value): bool

Verifica se a variável fornecida é um objeto.

Parâmetros

value

A variável a ser avaliada.

Valor Retornado

Retorna true se value for um object, false caso contrário.

Registro de Alterações

Versão Descrição
7.2.0 is_object() agora retorna true para objetos desserializados sem definição de classe (classe de __PHP_Incomplete_Class). Anteriormente false era retornado.

Exemplos

Exemplo #1 Exemplo de is_object()

<?php
// Declara uma função simples para retornar um
// array do nosso objeto
function get_students($obj)
{
if (!
is_object($obj)) {
return
false;
}

return
$obj->students;
}

// Declara uma nova instância de classe e preenche
// alguns valores
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');

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

Veja Também

  • is_bool() - Verifica se a variável é um booleano
  • is_int() - Informa se o tipo de uma variável é um inteiro
  • is_float() - Verifica se a variável é do tipo float
  • is_string() - Verifica se o tipo de uma variável é string
  • is_array() - Verifica se a variável é um array

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