ReflectionClass::getReflectionConstants

(PHP 7 >= 7.1.0)

ReflectionClass::getReflectionConstantsGets class constants

Descrierea

public ReflectionClass::getReflectionConstants ([ int|null $filter = null ] ) : array

Retrieves reflected constants.

Parametri

filter

The optional filter, for filtering desired constant visibilities. It's configured using the ReflectionClassConstant constants, and defaults to all constant visibilities.

Valorile întoarse

An array of ReflectionClassConstant objects.

Istoricul schimbărilor

Versiune Descriere
8.0.0 filter has been added.

Exemple

Example #1 Basic ReflectionClass::getReflectionConstants() example

<?php
class Foo {
    public    const 
FOO  1;
    protected const 
BAR  2;
    private   const 
BAZ  3;
}

$foo = new Foo();

$reflect = new ReflectionClass($foo);
$consts  $reflect->getReflectionConstants();

foreach (
$consts as $const) {
    print 
$const->getName() . "\n";
}

var_dump($consts);

?>

Exemplul de mai sus va afișa ceva similar cu:

FOO
BAR
BAZ
array(3) {
  [0]=>
  object(ReflectionClassConstant)#3 (2) {
    ["name"]=>
    string(3) "FOO"
    ["class"]=>
    string(3) "Foo"
  }
  [1]=>
  object(ReflectionClassConstant)#4 (2) {
    ["name"]=>
    string(3) "BAR"
    ["class"]=>
    string(3) "Foo"
  }
  [2]=>
  object(ReflectionClassConstant)#5 (2) {
    ["name"]=>
    string(3) "BAZ"
    ["class"]=>
    string(3) "Foo"
  }
}

A se vedea și

add a note add a note

User Contributed Notes

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