- var_dump: documentation ( source)
- is_numeric: documentation ( source)
- strtotime: documentation ( source)
<?php
function converTo($date, $format = 'Y-m-d', $default = null, callable $funcExc = null )
{
if (empty($date)) {
return $default;
}
if (!is_string($format)) {
throw new \InvalidArgumentException("Неверный формат");
}
try {
if (!($date instanceof \DateTime)) {
if (is_numeric($date) && ( strlen($timestamp) == 13 || strlen($timestamp) == 10 )) {
$date = new \DateTime("@" . $date);
} elseif (is_string($date) && (strtotime($date) !== false)) {
$date = new \DateTime("@" . strtotime($date));
} elseif(is_string($date)) {
$date = new \DateTime($date);
} else {
throw new \InvalidArgumentException("Не удалось распознать формат входящей даты");
}
}
if(!($date = $date->format($format))) {
throw new \InvalidArgumentException("Произошла ошибка при приведению к заданному формату: " . $format);
}
} catch (\Exception $e) {
if ($funcExc !== null) {
call_user_func($funcExc, $date);
}
throw $e;
}
return $date->format($format) ;
}
var_dump(converTo(['asda']));
die;
abstract class T
{
static public $instanses;
final private function __construct(){
}
public static function getInstance()
{
if (!(static::$instanses instanceof static)) {
static::$instanses = new static;
}
return static::$instanses;
}
}
class A extends T
{
static public $instanses;
}
class B extends A
{
static public $instanses;
}
$t = A::getInstance();
var_dump($t);
$t1 = B::getInstance();
var_dump($t1);
new B();
?>