ReflectionClass::isInstance

(PHP 5, PHP 7, PHP 8)

ReflectionClass::isInstanceChecks class for instance

Descrição

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

Checks if an object is an instance of a class.

Parâmetros

object

The object being compared to.

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Exemplos

Exemplo #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";
}
?>

O exemplo acima produzirá algo semelhante a:

Yes
Yes
Yes

Veja Também

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