views:

39

answers:

2

hey there i have a simple case of class with static variable and a get function all compile ok but at run time i am getting this error

[Sun Jul 25 03:57:07 2010] [error] [client 127.0.0.1] PHP Fatal error:  Undefined class constant 'TYPE' in .....

for the function getType()

here is my class

class NoSuchRequestHandler implements Handler{
    public static $TYPE  = 2001;
    public static $VER   = 0;

    public function getType(){
      return self::TYPE;
    }

    public function getVersion(){
      return self::VER;
    }
}

thank you all

+1  A: 

You can access this two ways since it is public...

class NoSuchRequestHandler implements Handler{ public static $TYPE = 2001; public static $VER = 0;

public function getType(){
  return self::$TYPE;  //not the "$" you were missing.  
}

public function getVersion(){
  return self::$VER;
}

}

echo NoSuchRequestHandler::$TYPE; //outside of the class.

Chris
thank you very much
shay
@chris Fix the formatting, and I'll gladly +1 the answer.
George Marian
+2  A: 

PHP thinks you're trying to access a class constant because of:

return self::TYPE;

http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php

As Chris mentions, use:

return self::$TYPE;
George Marian