GoLang ReflectionClass::isInstantiable

request it (281)
GoLang replacement for PHP's ReflectionClass::isInstantiable [edit | history]



Do you know a GoLang replacement for PHP's ReflectionClass::isInstantiable? Write it!

PHP ReflectionClass::isInstantiable

PHP original manual for ReflectionClass::isInstantiable [ show | php.net ]

ReflectionClass::isInstantiable

(PHP 5, PHP 7)

ReflectionClass::isInstantiableChecks if the class is instantiable

Description

public bool ReflectionClass::isInstantiable ( void )

Checks if the class is instantiable.

Parameters

This function has no parameters.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

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

?>

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