ReflectionClass::isInstantiable

(PHP 5, PHP 7)
Checks if the class is instantiable
public bool ReflectionClass::isInstantiable ( void )

Checks if the class is instantiable.

Returns:

Returns TRUE on success or FALSE on failure.

Examples:
ReflectionClass::isInstantiable() example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class C { }
 
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()); 
}
 
?>

The above example will output:

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)
See also:

ReflectionClass::isInstance() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.