PHP 8.3.7 Released!

ReflectionClass::getReflectionConstants

(PHP 7 >= 7.1.0, PHP 8)

ReflectionClass::getReflectionConstantsObtém constantes de classe

Descrição

public ReflectionClass::getReflectionConstants(?int $filter = null): array

Recupera constantes refletidas.

Parâmetros

filter

O filtro opcional, para filtrar as visibilidades constantes desejadas. Está configurado usando as constantes ReflectionClassConstant, e o padrão é todas as visibilidades constantes.

Valor Retornado

Um array de objetos ReflectionClassConstant.

Registro de Alterações

Versão Descrição
8.0.0 filter foi adicionado.

Exemplos

Exemplo #1 Exemplo básico de ReflectionClass::getReflectionConstants()

<?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);

?>

O exemplo acima produzirá algo semelhante a:

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"
  }
}

Veja Também

add a note

User Contributed Notes

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