
MongoDBBSONTimestampInterface 클래스의 __toString 메소드는 Timestamp 객체를 문자열로 변환하는 역할을 합니다.
이 메소드는 Timestamp 객체의 timestamp, increment, 시각, 시간대, 타임존을 문자열로 변환하여 반환합니다.
예를 들어, Timestamp 객체가 다음과 같이 생성되었다고 가정해 보겠습니다.
#hostingforum.kr
php
$timestamp = new MongoDBBSONUTCDateTime();
이 경우, __toString 메소드를 호출하면 다음과 같은 문자열이 반환됩니다.
#hostingforum.kr
php
$timestamp->__toString();
이 메소드를 오버라이딩 하는 방법은 다음과 같습니다.
#hostingforum.kr
php
class MyTimestamp extends MongoDBBSONTimestamp {
public function __toString() {
// 원하는 로직을 구현합니다.
return 'My custom timestamp string';
}
}
이렇게 오버라이딩 한 후, MyTimestamp 객체를 생성하고 __toString 메소드를 호출하면 다음과 같은 문자열이 반환됩니다.
#hostingforum.kr
php
$myTimestamp = new MyTimestamp();
echo $myTimestamp->__toString(); // My custom timestamp string
2025-08-03 20:40