class Status { const PENDING = 'pending'; const APPROVED = 'approved'; const DECLINED = 'declined'; } $reflectionClass = new ReflectionClass(Status::class); $statusConstants = $reflectionClass->getConstants(); print_r($statusConstants);
Array ( [PENDING] => pending [APPROVED] => approved [DECLINED] => declined )
$reflectionClass = new ReflectionClass(DateTime::class); $dateConstants = $reflectionClass->getConstants(); print_r($dateConstants);
Array ( [ATOM] => Y-m-d\TH:i:sP [COOKIE] => l, d-M-Y H:i:s T [ISO8601] => Y-m-d\TH:i:sO [RFC822] => D, d M y H:i:s O [RFC850] => l, d-M-y H:i:s T [RFC1036] => D, d M y H:i:s O [RFC1123] => D, d M Y H:i:s O [RFC2822] => D, d M Y H:i:s O [RFC3339] => Y-m-d\TH:i:sP [RFC3339_EXTENDED] => Y-m-d\TH:i:s.vP [RSS] => D, d M Y H:i:s O [W3C] => Y-m-d\TH:i:sP )This example demonstrates how to use the ReflectionClass getConstants method to retrieve the constants defined in the PHP DateTime class. From the examples given, it seems that this function is included in the standard PHP library.