PHP Doku:: Gets constants - reflectionclass.getconstants.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenReflectionThe ReflectionClass classReflectionClass::getConstants

Ein Service von Reinhard Neidl - Webprogrammierung.

The ReflectionClass class

<<ReflectionClass::getConstant

ReflectionClass::getConstructor>>

ReflectionClass::getConstants

(PHP 5)

ReflectionClass::getConstantsGets constants

Beschreibung

public array ReflectionClass::getConstants ( void )

Gets defined constants from a class.

Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

Parameter-Liste

Diese Funktion hat keine Parameter.

Rückgabewerte

An array of constants.

Siehe auch


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
djhob1972 at yahoo dot com dot au
16.12.2009 14:42
I was trying to determine how to get a var_dump of constants that are within an interface.  Thats right, not using any classes but the interface itself.

Along my travels I found it quite interesting that the ReflectionClass along with a direct call to the interface will also dump its constants.  Perfect!!!!

This was using PHP 5.3.1 and my example as below:-

1st File:

constants.php

<?php
<?php>

interface
MyConstants
{
   
// --------------------------
    // Programmatic Level
    // --------------------------
   
const DEBUG_MODE_ACTIVE       = FALSE;
    const
PHP_VERSION_REQUIREMENT = "5.1.2";
}
?>

=======
Second file:
=======

test.php

<?php>
include_once (
"constants.php");

$oClass = new ReflectionClass ('MyConstants');
$array = $oClass->getConstants ();
var_dump ($array);
unset (
$oClass);
?>

what you would get from the command line:-

?:\???\htdocs\????>php test.php
array(2) {
  ["DEBUG_MODE_ACTIVE"]=> bool(false)
  ["PHP_VERSION_REQUIREMENT"]=> string(5) "5.1.2"

But as you can see this can work quite well to your advantage in many ways so I truely hope this helps someone else with a similar headache in the future to come!

Enjoy!



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)