모던php 사용시 흔하게 볼 수 있는 한가지 static
모던PHP에서 클래스를 생성하지 않고 메소드를 직접 호출 할때 흔하게 볼 수 있는 오류 입니다.
메시지 내용에서 알 수 있듯이 static 선언이 안되서 그렇습니다. 즉, 이 선언이 된 것만 가능하다.
$d = new DateTime();
echo $d->format('Y-m-d'). "\n";
$d->setDate(2022, 2, 3);
echo $d->format('Y-m-d'). "\n";
$ts = 1383458399; /* 2013-11-03 01:59:59 in Eastern Saving Time */
$dst = DateTime::createFromFormat('U',$ts, new DateTimeZone('GMT'));
$oDate = $dst->setDate(2022,2,2);
$oDate = $dst->setTime(11, 11, 11, 0);
echo '출력: ' . $oDate->format('Y-m-d H:i:s') . "\n";
// 아래는 static가 아니라서 안되는 것이다. 아래를 보게 된다.
// PHP Fatal error: Uncaught Error: Non-static method DateTime::setDate() cannot be called statically
$oDate = DateTime::setDate(2022,11,11);
* 이중콜론에 대해선 아래를 참고
- PHP를 쉘에서 실행 시킬때(CLI 환경) restart 시키는 방법 > PHP