My class looks similar to this:
class Foo {
const UNKNOWN = 2;
public function doStuff($var) {
if($var==UNKNOWN) {
echo "Unknown state";
return;
}
// other stuff
}
}
However, I'm getting this error in doStuff():
Use of undefined constant UNKNOWN - assumed 'UNKNOWN'
What am I doing wrong? Can't I define custom constants?
You must use self:: or the class name when accessing the constant in your class:
if($var == self::UNKNOWN) {
echo "Unknown state";
return;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With