0

Here's my var, it's a const:

const TWITTER_CACHE_REFRESH = 1440;

How can I access it in a method in the same class that I declare it? The class it's in has already been initialized by another class.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
panthro
  • 22,779
  • 66
  • 183
  • 324

1 Answers1

2

Use the following syntax

echo self::CONSTNAME;

In your case:

echo self::TWITTER_CACHE_REFRESH;

You can also replace self with the class name if you wish but it is not recommended as if you change the class name then you have to change all references to its name in your code.

echo Classname::TWITTER_CACHE_REFRESH;
John Conde
  • 217,595
  • 99
  • 455
  • 496