<p>This is how I wanted to do it which would work in PHP 5.3.0+</p>

<pre><code>&lt;?php
    class MyClass
    {
        const CONSTANT = 'Const var';        
    }

    $classname = 'MyClass';
    echo $classname::CONSTANT; // As of PHP 5.3.0
?&gt;
</code></pre>

<p>But I'm restricted to using PHP 5.2.6. Can anyone think of a simple way to simulate this behavior without instantiating the class?</p>

[{'answer_id': 5472, 'author': 'Juan', 'author_id': 550, 'author_profile': 'https://Stackoverflow.com/users/550', 'pm_score': -1, 'selected': False, 'text': "<p>If you absolutly need to access a constant like that, you can do this:</p>\n\n<pre><code>&lt;?php\nclass MyClass\n{\n        const CONSTANT = 'Const var';\n}\n\n$classname = 'MyClass';\necho eval( 'return '.$classname.'::CONSTANT;' );\n?&gt;\n</code></pre>\n\n<p>But, if i were you, I'd try not to use eval.</p>\n"}, {'answer_id': 19601, 'author': 'AdamTheHutt', 'author_id': 1103, 'author_profile': 'https://Stackoverflow.com/users/1103', 'pm_score': 4, 'selected': True, 'text': '<p>You can accomplish this without using <a href="http://php.net/manual/en/function.eval.php" rel="nofollow noreferrer"><code>eval</code></a> in pre-5.3 code. Just use the <a href="http://php.net/manual/en/function.constant.php" rel="nofollow noreferrer"><code>constant</code></a> function:</p>\n\n<pre><code>&lt;?php\n\nclass MyClass\n{\n    const CONSTANT = \'Const var\';\n}\n\n$classname = \'MyClass\';\necho constant("$classname::CONSTANT");\n\n?&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/5459', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/117/']