ReflectionClass::isInstantiable
ReflectionClass::isInstantiable
(PHP 5, PHP 7)
ReflectionClass::isInstantiable - 检查类是否可实例化
描述
public bool ReflectionClass::isInstantiable ( void )
检查该类是否可实例化。
参数
该函数没有参数。
返回值
成功时返回TRUE
或失败时返回FALSE
。
例子
示例#1 ReflectionClass::isInstantiable()示例
<?php
class C { }
interface iface {
function f1(
}
class ifaceImpl implements iface {
function f1() {}
}
abstract class abstractClass {
function f1() { }
abstract function f2(
}
class D 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)
另请参阅
- ReflectionClass::isInstance() - 检查类的实例
← ReflectionClass::isInstance
ReflectionClass::isInterface →