PHP 5.4.31 Released

ReflectionClass::isInstantiable

(PHP 5)

ReflectionClass::isInstantiableChecks if the class is instantiable

Descrição

public bool ReflectionClass::isInstantiable ( void )

Checks if the class is instantiable.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em caso de falha.

Exemplos

Exemplo #1 ReflectionClass::isInstantiable() example

<?php
class { }

interface 
iface {
    function 
f1();
}

class 
ifaceImpl implements iface {
    function 
f1() {}
}

abstract class 
abstractClass {
    function 
f1() { }
    abstract function 
f2();
}

class 
extends abstractClass {
    function 
f2() { }
}

class 
privateConstructor {
    private function 
__construct() { }
}

$classes = array(
    
"C",
    
"iface",
    
"ifaceImpl",
    
"abstractClass",
    
"D",
    
"privateConstructor",
);

foreach(
$classes  as $class ) {
    
$reflectionClass = new ReflectionClass($class);
    echo 
"Is $class instantiable?  ";
    
var_dump($reflectionClass->IsInstantiable()); 
}

?>

O exemplo acima irá imprimir:

Is C instantiable?  bool(true)
Is iface instantiable?  bool(false)
Is ifaceImpl instantiable?  bool(true)
Is abstractClass instantiable?  bool(false)
Is D instantiable?  bool(true)
Is privateConstructor instantiable?  bool(false)

Veja Também

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top