How php is defined as a variable in a class with a string constant and a string

68 4

There's already a constant data path, and a string & file_name"

How to define a variable in a class ( constant looks like 5. 7 ), representing the combination of data path and file_name.

I'm in the class, like this:

$FILE_PATH = DATA_PATH."file_name";

But not in the class:

class Util {
 public static $FILE_PATH = DATA_PATH."file_name";//语法错误
}

Find other ways to upgrade php versions

5 Answers

150 4

The original meaning of the question is that it isn't necessary to call this static attribute directly by the Util::$FILE_PATH.

Yes, in addition to upgrading to php v5.6.0, it's written directly:

define('DATA_PATH', __DIR__. DIRECTORY_SEPARATOR);
class Util {
 public static function getFilePath() {
 return DATA_PATH. 'filename';
 }
}
echo Util::getFilePath();
...