PHP Velho Oeste 2024

is_object

(PHP 4, PHP 5, PHP 7)

is_object변수가 객체인지 확인합니다

설명

bool is_object ( mixed $var )

주어진 변수가 객체인지 확인합니다.

인수

var

평가할 변수.

반환값

varobjectTRUE를, 아니라면 FALSE를 반환합니다.

예제

Example #1 is_object() 예제

<?php
// 객체에서 배열을 반환하는
// 간단한 함수를 선언합니다.
fucntion get_students($obj)
{
        if(!
is_object($obj))
        {
                return(
false);
        }

        return(
$obj->students);
}

// 새 클래스를 선언하고
// 값을 채웁니다.
$obj = new stdClass;
$obj->students = Array('Kalle''Ross''Felipe');

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

주의

Note:

클래스 정의가 존재하지 않는 일렬화를 푼 객체에 대해서 FALSE를 반환합니다. (gettype()object를 반환합니다)

참고

  • is_bool() - 변수가 논리형인지 확인
  • is_int() - 변수의 자료형이 정수인지 확인합니다
  • is_float() - 변수의 자료형이 소수인지 확인합니다
  • is_string() - 변수의 자료형이 문자열인지 확인합니다
  • is_array() - 변수가 배열인지 확인

add a note add a note

User Contributed Notes 2 notes

up
94
peter dot nagel at portavita dot nl
13 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