- var_dump: documentation ( source)
- print_r: documentation ( source)
- serialize: documentation ( source)
- date: documentation ( source)
<?php
class Tester
{
private $code = 0;
static private $instance;
private function __construct()
{
}
static public function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
private $errors = array();
public function addError($txt, $code = 1) {
$this->errors[] = ['txt' => $txt, 'code' => $code, 'tm' => date('Y-m-d H:i:s')];
if ($this->code === 0) {
$this->code = $code;
}
}
public function countErrors()
{
return count($this->errors);
}
public function valid()
{
return empty($this->errors) ? '0' : ($this->code != 0 ? $this->code : '999');
}
public function showErrors()
{
return print_r($this->errors,1);
}
public function __toString()
{
return $this->showErrors();
}
}
$tester = Tester::getInstance();
$s = serialize($tester);
$d = deserialize($s);
var_dump($d);