tags:

views:

25

answers:

2

Hello

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

A: 

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
Sarfraz
PHP5. I can add variable that way, but then I can't call it like `$this->variable` if I don't create the object like this: `$asd = new Errsys;` Any other ways to call it?
Martti Laine
Errsys::$variable
Bart van Heukelom
you call with with self http://stackoverflow.com/questions/151969/php-self-vs-this
ebt
Thanks for ebt solving my problem. sAc gets the points x)
Martti Laine
+1  A: 

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 :)

Jani Hartikainen