我真的希望我在这里错过了一些简单的事情,但是在PHP中使用类常量遇到了一个奇怪的问题。我创建了一个名为Utils的简单类,并添加了两个类常量CRYPT_SALT和LOGIN_PAGE。我从其他文件中引用了这些文件,并且它们起作用了。然后,我又添加了五个类常量,它们不起作用。我在“ /var/www/modx/test.php”行中收到“致命错误:未定义的类常量”,其中是新常量之一,也是我尝试使用它的行。
这是Utils类:
<?php
//
// Utils.php
//
// This class is a collection of static utility functions. Since the methods are static, they should
// all be invoked with:
//
// Utils::methodName();
//
// This class also contains global constants, which are *not* kept in Config. They should be accessed with:
//
// Utils::CONSTANT;
//
// addToCSVString -- adds an incoming string to a CSV string, possibly prepending a comma and space. Returns
// addToJSONString -- adds an incoming …Run Code Online (Sandbox Code Playgroud)