简体   繁体   中英

php static properties and methods

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM