I am from Java background and have switched to php for one project recently. I have found one unexpected behaviour in php.
No, while a static variable will stay for the current request you'll need to add it to a session to persist it's value across requests.
Example:
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'] . '
';