0

define as follows

class Timer{
    private static $timeRemaining;
    private static $timeLimit;
    private static $nextTime;

    static function block();
    static function updateCookies();
}

when going around between webpages, how long do those static properties and methods live? As a result, which one is better, using the class above or a singleton object?

addlistener
  • 871
  • 1
  • 12
  • 20

1 Answers1

0

They live as much as PHP executes a code - while request lives.

And of course, between webpages all data is erased. But you can use session and manually assign data to static variables or non-static instance variables.

Singletons use a static variable as a storage of instance.

sybear
  • 7,837
  • 1
  • 22
  • 38
  • You've explained them clearly enough, but I'd like to ask would it be robust if I use session in the class's destructor? like __destructor{$_SESSION['time_remaining'] = $timeRemaining;} ??? – addlistener Apr 05 '13 at 16:57
  • It is possible, of course, but I'd recommend you using it in constructor instead : D – sybear Apr 05 '13 at 17:17