Store the object in a session. To do this, your object must implement the __ sleep () / __ wakeup () functions .
, , __wakeup(). :
:
<?php
class User {
private $user_id;
function getFromID($id) {... doing something; }
function __wakeup() {
$this->getFromID($this->user_id);
}
}
/ ;
<?php
$current_user = $_SESSION['user'];
if(!$current_user) $current_user = new User();
...
$_SESSION['user'] = $current_user;