Why does the following code give me an exception saying that my constant isn't defined
MyClass::myFunction(MyClass::MY_CONST); // THIS GIVES THE ERROR
// This is the class..
class MyClass {
const MY_CONST = 'BLA';
public static function myFunction($key) {
if (!defined($key)) {
throw new Exception("$key is not defined as a constant");
}
}
}
I've tried with
if (!defined($key)) {}if (!defined(self::$key)) {}if (!defined(__CLASS__ . $key)) {}
MY_CONSTwasn't defined, you wouldn't be able to use it in your first line