ReflectionClass::isInstance

(PHP 5, PHP 7)

ReflectionClass::isInstanceChecks class for instance

설명

public bool ReflectionClass::isInstance ( object $object )

Checks if an object is an instance of a class.

인수

object

The object being compared to.

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 ReflectionClass::isInstance() related examples

<?php
// Example usage
$class = new ReflectionClass('Foo');

if (
$class->isInstance($arg)) {
    echo 
"Yes";
}

// Equivalent to
if ($arg instanceof Foo) {
    echo 
"Yes";
}

// Equivalent to
if (is_a($arg'Foo')) {
    echo 
"Yes";
}
?>

위 예제의 출력 예시:

Yes
Yes
Yes

참고

add a note add a note

User Contributed Notes 1 note

up
0
dhairya lakhera
8 years ago
class  TestClass { }

$TestObj=new TestClass();

$TestObj_assigned=$TestObj;
$TestObj_Refrenced=&$TestObj;
$TestObj_cloned=clone $TestObj;

$obj=new ReflectionClass('TestClass');

var_dump($obj->isInstance($TestObj));
var_dump($obj->isInstance($TestObj_assigned));
var_dump($obj->isInstance($TestObj_Refrenced));
var_dump($obj->isInstance($TestObj_cloned));
To Top