PHP 8.4.2 Released!

ReflectionClass::hasConstant

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

ReflectionClass::hasConstantChecks if constant is defined

Description

public ReflectionClass::hasConstant(string $name): bool

Checks whether the class has a specific constant defined or not.

Parameters

name

The name of the constant being checked for.

Return Values

true if the constant is defined, otherwise false.

Examples

Example #1 ReflectionClass::hasConstant() example

<?php
class Foo {
const
c1 = 1;
}

$class = new ReflectionClass("Foo");

var_dump($class->hasConstant("c1"));
var_dump($class->hasConstant("c2"));
?>

The above example will output something similar to:

bool(true)
bool(false)

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top