update : 2015.11.03
php.shukuma.com

검색:
 
 
Checks if the class is instantiable

ReflectionClass::isInstantiable

(PHP 5)

ReflectionClass::isInstantiableChecks if the class is instantiable

설명

public bool ReflectionClass::isInstantiable ( void )

Checks if the class is instantiable.

인수

이 함수는 인수가 없습니다.

반환값

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

예제

Example #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()); 
}

?>

위 예제의 출력:

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)

참고