1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?php
class User
{
protected $_login;
protected $_pass;
protected $_status = 0;
protected $_level = 0;
protected $_fp;
protected static $_logFile = "log.log";
const LOG_FORMAT = "Message de log (%d) - *%s*";
public function __construct($login = 'root', $pass = 'secret')
{
$this->_login = $login;
$this->_pass = $pass;
$this->_fp = fopen(__DIR__ . '/' . self::$_logFile, "a");
$this->_writeToLog(" construction");
}
public function __wakeup()
{
$this->_fp = fopen(__DIR__ . '/' . self::$_logFile, "a");
$this->_writeToLog("désérialisation");
}
protected function _writeToLog($message)
{
fwrite($this->_fp, sprintf(self::LOG_FORMAT, time(), $message) . PHP_EOL);
} |