PHP | ReflectionClass isInstantiable() Function
Last Updated :
17 Dec, 2019
Improve
The ReflectionClass::isInstantiable() function is an inbuilt function in PHP which is used to check the specified class is instantiable or not.
Syntax:
php
php
bool ReflectionClass::isInstantiable( void )Parameters: This function does not accept any parameters. Return Value: This function returns TRUE if the specified class is instantiable, otherwise return FALSE. Below programs illustrate the ReflectionClass::isInstantiable() function in PHP: Program 1:
<?php
// Initializing a user-defined Class Departments
class Departments {
public function CSE() { }
}
// Using ReflectionClass() over the
// user-defined class Departments
$class = new ReflectionClass('Departments');
// Calling the isInstantiable() function
$instance = $class->isInstantiable();
// Getting the value true or false
var_dump($instance);
?>
<?php
// Initializing a user-defined Class Departments
class Departments {
public function CSE() { }
}
// Using ReflectionClass() over the
// user-defined class Departments
$class = new ReflectionClass('Departments');
// Calling the isInstantiable() function
$instance = $class->isInstantiable();
// Getting the value true or false
var_dump($instance);
?>
Output:
Program 2:
bool(true)
<?php
// Initializing a interface named as TestFunction
interface TestFunction {
function F1();
function F2();
}
// Using ReflectionClass() over the
// specified interface
$class = new ReflectionClass('TestFunction');
// Calling the isInstantiable() function and
// getting the value true or false
var_dump($class->isInstantiable());
?>
<?php
// Initializing a interface named as TestFunction
interface TestFunction {
function F1();
function F2();
}
// Using ReflectionClass() over the
// specified interface
$class = new ReflectionClass('TestFunction');
// Calling the isInstantiable() function and
// getting the value true or false
var_dump($class->isInstantiable());
?>
Output:
Reference: https://www.php.net/manual/en/reflectionclass.isinstantiable.php
bool(false)