array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'de', ), 'this' => array ( 0 => 'reflectionclass.isinstantiable.php', 1 => 'ReflectionClass::isInstantiable', 2 => 'Checks if the class is instantiable', ), 'up' => array ( 0 => 'class.reflectionclass.php', 1 => 'ReflectionClass', ), 'prev' => array ( 0 => 'reflectionclass.isinstance.php', 1 => 'ReflectionClass::isInstance', ), 'next' => array ( 0 => 'reflectionclass.isinterface.php', 1 => 'ReflectionClass::isInterface', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/reflection/reflectionclass/isinstantiable.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

ReflectionClass::isInstantiable

(PHP 5, PHP 7, PHP 8)

ReflectionClass::isInstantiableChecks if the class is instantiable

Beschreibung

public ReflectionClass::isInstantiable(): bool

Checks if the class is instantiable.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Gibt bei Erfolg true zurück. Bei einem Fehler wird false zurückgegeben.

Beispiele

Beispiel #1 ReflectionClass::isInstantiable() example

<?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() { }
}

trait
T {
function
f1() {}
}

class
privateConstructor {
private function
__construct() { }
}

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

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

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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 T instantiable?  bool(false)
Is privateConstructor instantiable?  bool(false)

Siehe auch