session_start() 是否必须在类的每个函数中调用?喜欢:
class User {
var $username;
function set_session_username($username) {
session_start(); # do I really need to call this again?
$_SESSION['username'] = $username;
}
function retrieve_session_username() {
session_start(); # do I really need to call this again?
$this -> username = $_SESSION['username'];
}
}
session_start();
$user = new User();
$user -> set_session_username('savagewood');
$user -> retrieve_session_username();
echo $user -> username;