Welcome Guest, Not a member yet? Register   Sign In
Constant in a class

Hey there

I wonder how I could access a constant in a class/library from outside through CI's loading mechanics:

//library lib_test.php
const SOME_CONSTANT    = 0;

Now, in a controller, this doesn't work:
echo $this->lib_test::CONSTANT;    //Parse-error
echo $this->lib_test->CONSTANT;    //No parse-error, but neither a result

Any suggestion how to access constants (or class-vars)?


From my reading of it you'd want to use:

echo lib_test::CONSTANT

The first method you've attempted is fine in php 5.3 apparently. The second will read the object variables. You can read more on object constants in the [url-http://uk.php.net/manual/en/language.oop5.constants.php]php manual[/url]

You should also note that libraries should be capitalised...User guide

stupid, I didn't think of leaving away '$this' :rolleye: ... about the rest you wrote I'm perfectly well informed, I was just fast-typing. Thx mate.

No worries, sorry if i came across patronising!

Theme © iAndrew 2016 - Forum software by © MyBB