is_object

(PHP 4, PHP 5)

is_objectFinds whether a variable is an object

Description

bool is_object ( mixed $var )

Finds whether the given variable is an object.

Parameters

var

The variable being evaluated.

Return Values

Returns TRUE if var is an object, FALSE otherwise.

Examples

Example #1 is_object() example

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

    return 
$obj->students;
}

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

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

Notes

Note:

This function will return FALSE if used on an unserialized object where the class definition is not present (even though gettype() returns object).

See Also

  • is_bool() - Finds out whether a variable is a boolean
  • is_int() - Find whether the type of a variable is integer
  • is_float() - Finds whether the type of a variable is float
  • is_string() - Find whether the type of a variable is string
  • is_array() - Finds whether a variable is an array

Коментарии

Note: is_object(null) returns false

This should actually be part of the input/output specification at the top of this page.
2011-03-22 03:46:48
http://php5.kiev.ua/manual/ru/function.is-object.html
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;
}
?>
2011-09-21 15:23:15
http://php5.kiev.ua/manual/ru/function.is-object.html

    Поддержать сайт на родительском проекте КГБ