public function addConstant($name, $value, $overrideOnDefined = false)
    {
        if ($this->classConstants->offsetExists($name) === true) {
            if ($overrideOnDefined === false) {
                throw Exception\ClassFile::constantAlreadyDefined($this->className, $name);
            }

            $this->classConstants->offsetUnset($name);
        }

        if (
            PHPUtils::isReservedAny($name) === true ||
            (((bool) preg_match('/^[^a-zA-Z_]/', $name)) === true)
        ) {
            throw Exception\ClassFile::invalidConstantName($this->className, $name);
        }

        $classConstant = new Element\ClassConstant($name, $value);
        $this->classConstants->offsetSet($name, $classConstant);

        return $classConstant;
    }
public function addConstant($name, $value, $overrideOnDefined = false)
    {
        if ($this->classConstants->offsetExists($name) === true) {
            if ($overrideOnDefined === false) {
                throw Exception\ClassFile::constantAlreadyDefined($this->className, $name);
            }

            $this->classConstants->offsetUnset($name);
        }

        if (
            PHPUtils::isReservedAny($name) === true ||
            (((bool) preg_match('/^[^a-zA-Z_]/', $name)) === true)
        ) {
            throw Exception\ClassFile::invalidConstantName($this->className, $name);
        }

        $classConstant = new Element\ClassConstant($name, $value);
        $this->classConstants->offsetSet($name, $classConstant);

        return $classConstant;
    }
public function addConstant ( $ name , $ value , $ overrideOnDefined = false ) { if ( $ this -> classConstants -> offsetExists ( $ name ) === true ) { if ( $ overrideOnDefined === false ) { throw Exception \ ClassFile :: constantAlreadyDefined ( $ this -> className , $ name ) ; } $ this -> classConstants -> offsetUnset ( $ name ) ; } if ( PHPUtils :: isReservedAny ( $ name ) === true || ( ( ( bool ) preg_match ( '/^[^a-zA-Z_]/' , $ name ) ) === true ) ) { throw Exception \ ClassFile :: invalidConstantName ( $ this -> className , $ name ) ; } $ classConstant = new Element \ ClassConstant ( $ name , $ value ) ; $ this -> classConstants -> offsetSet ( $ name , $ classConstant ) ; return $ classConstant ; }
Add a new class constant

@param string $name
@param string $value
@param bool   $overrideOnDefined

@return Element\ClassConstant
@throws Exception\ClassFile
Add a new class constant