konst ( $class, $const )

Retrieves the value of a class constant, while avoiding the T_PAAMAYIM_NEKUDOTAYIM error. Misspelled because const is a reserved word.

Access

public

Parameters

Parameter

Type

Required

Description

$class

object

Required

An instance of the class containing the constant.

$const

string

Required

The name of the constant to retrieve.

Returns

Type

Description

mixed

The value of the class constant.

Examples

Very simple example of konst().

$s3 = new AmazonS3();
$rfc2616 = $s3->util->konst($s3->util, 'DATE_FORMAT_RFC2616');
$date = gmdate($rfc2616, 946684800);

var_dump($date);
Result:
string(29) "Sat, 01 Jan 2000 00:00:00 GMT"

Source

Method defined in utilities/utilities.class.php | Toggle source view (13 lines) | View on GitHub

public function konst($class, $const)
{
    if (is_string($class))
    {
        $ref = new ReflectionClass($class);
    }
    else
    {
        $ref = new ReflectionObject($class);
    }

    return $ref->getConstant($const);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback