Constant in a class

#1
[eluser]sl3dg3hamm3r[/eluser]
Hey there

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

Code:
[...]
//library lib_test.php
const SOME_CONSTANT    = 0;

Now, in a controller, this doesn't work:
Code:
$this->load->library('lib_test'));
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)?

Sl3dg3

#2
[eluser]roj[/eluser]
From my reading of it you'd want to use:

Code:
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

#3
[eluser]sl3dg3hamm3r[/eluser]
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.

#4
[eluser]roj[/eluser]
No worries, sorry if i came across patronising!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.