不,虽然静态变量将保留当前请求,但您需要将其添加到会话中以在请求之间保持其值.
例:
session_start(); class Car { public static $make; public function __construct($make) { self::$make = $make; } } $c = new Car('Bugatti'); echo '' . Car::$make . '
'; unset($c); if (!isset($_SESSION['make'])) { echo '' . Car::$make . '
'; $c = new Car('Ferrari'); echo '' . Car::$make . '
'; } $_SESSION['make'] = Car::$make; echo '' . $_SESSION['make'] . '
';