如何在php中添加类中的公共var?

I currently have a error-system like this on my header.php:

include('class.error.php');
Errsys::disable_default();
Errsys::enable_logging('errors.dat');

So, I'm not creating a new object via $asd = new Errsys;. How to add a variable to class, so it can be called like Errsys::variable or via any similar syntax inside or outside the class?

Hope you understood.

Martti Laine

Which version of php are you using? You can add a class variable like:

class className {
  public $varname;
  ............ more code

In static context:

class className {
  public static $varname;
  ............ more code

You can create a static variable similar to creating a static function:

public static $whatever;

I would recommend reading PHP manual's section on classes and objects for further information.

ps. If your class is called Errsys, I'd recommend calling the file class.errsys.php as well instead of class.error.php :)