PHP const not working?

class, constants, php

Solution

You must use `self::` or the class name when accessing the constant in your class:

if($var == self::UNKNOWN) {
    echo "Unknown state";
    return;
}

Problem

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?

Original source