« ReflectionClass::isFinal
ReflectionClass::isInstantiable »

ReflectionClass::isInstance

(PHP 5, PHP 7, PHP 8)

ReflectionClass::isInstance — クラスのインスタンスであるかどうかを調べる

説明

public function ReflectionClass::isInstance(object $object): bool

あるオブジェクトがクラスのインスタンスであるかどうかを調べます。

パラメータ

object

比べたいオブジェクト。

戻り値

オブジェクトがクラスのインスタンスの場合は、true を返します。 そうでない場合は、false を返します。

例

例1 ReflectionClass::isInstance() の例

<?php

class Foo {}

$object = new Foo();

$reflection = new ReflectionClass('Foo');

if ($reflection->isInstance($object)) {
    echo "Yes\n";
}

// これも同じ意味です
if ($object instanceof Foo) {
    echo "Yes\n";
}

// これも同じ意味です
if (is_a($object, 'Foo')) {
    echo "Yes";
}
?>

上の例の出力は、 たとえば以下のようになります。

Yes
Yes
Yes

参考

関連キーワード:
ReflectionClass   インスタンス   isInstance   reflection   意味   instanceof   インターフェイス   isFinal   isInstantiable   参考   isInterface   演算子
関連する関数・ページ:
reflectionclass.isinterface   reflectionclass.getparentclass   reflectionclass.isfinal   reflectionclass.getfilename   reflectionclass.issubclassof   reflectionclass.isuserdefined