array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'reflectionclass.hasconstant.php', 1 => 'ReflectionClass::hasConstant', ), 'up' => array ( 0 => 'class.reflectionclass.php', 1 => 'ReflectionClass', ), 'prev' => array ( 0 => 'reflectionclass.gettraits.php', 1 => 'ReflectionClass::getTraits', ), 'next' => array ( 0 => 'reflectionclass.hasmethod.php', 1 => 'ReflectionClass::hasMethod', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/reflection/reflectionclass/hasconstant.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
ReflectionClass::hasConstant — Comprueba si una constante está o no definida
Comprueba si la constante especificada está o no definida en la clase.
name
Nombre de la constante que se desea comprobar.
Ejemplo #1 Ejemplo de ReflectionClass::hasConstant()
<?php
class Foo {
const c1 = 1;
}
$class = new ReflectionClass("Foo");
var_dump($class->hasConstant("c1"));
var_dump($class->hasConstant("c2"));
?>
El resultado del ejemplo sería algo similar a:
bool(true) bool(false)