PHPSA\Definition\RuntimeClassDefinition::hasConst PHP Method

hasConst() public method

public hasConst ( string $name, boolean $inherit = false ) : boolean
$name string
$inherit boolean
return boolean
    public function hasConst($name, $inherit = false)
    {
        if (!$this->reflection->hasConstant($name)) {
            return false;
        }
        // NOTE: ReflectionClass::hasConstant also checks parent classes, so if $inherit is true, the job is already done.
        if ($inherit) {
            return true;
        }
        // but if it's not, we need to make sure that the constant is defined only in the current class. It means that
        // we have to check that it has no parent or that the parent does not define the constant.
        $parent = $this->reflection->getParentClass();
        if (!$parent) {
            return true;
        }
        return !$parent->hasConstant($name);
    }

Usage Example

Exemplo n.º 1
0
 public function testHasConstWithParent()
 {
     $reflection = new ReflectionClass(Parameter::class);
     $definition = new RuntimeClassDefinition($reflection);
     static::assertFalse($definition->hasConst('BRANCH_ROOT'));
     static::assertTrue($definition->hasConst('BRANCH_ROOT', true));
 }
All Usage Examples Of PHPSA\Definition\RuntimeClassDefinition::hasConst