Menu Home

trait_exists

osbo.com | PHP | Functions | trait_exists

Checks if the trait exists

Syntax

trait_exists ( string $traitname [, bool $autoload ] ) : bool

Parameters

traitname

Name of the trait to check

autoload

Whether to autoload if not already loaded.

Return

Returns TRUE if trait exists, FALSE if not, NULL in case of an error.

Examples

traitname

<?

trait mytrait
{
}

$traitname = "mytrait";

$return = trait_exists($traitname);

var_export($return);

?>
true

autoload | false

<?

trait mytrait
{
}

$traitname = "mytrait";
$autoload = false;

$return = trait_exists($traitname, $autoload);

var_export($return);

?>
true

autoload | true

<?

trait mytrait
{
}

$traitname = "mytrait";
$autoload = true;

$return = trait_exists($traitname, $autoload);

var_export($return);

?>
true

PHP