
MongoDBBSONTimestampInterface 클래스의 __toString 메서드는 Timestamp 객체를 문자열로 변환하는 역할을 합니다.
이 메서드는 Timestamp 객체의 timestamp, increment, 로컬 타임존, UTC 타임존을 문자열로 변환하여 반환합니다.
__toString 메서드를 오버라이딩하는 방법은 다음과 같습니다.
#hostingforum.kr
php
class CustomTimestamp implements MongoDBBSONTimestampInterface {
private $timestamp;
private $increment;
private $localTimezone;
private $utcTimezone;
public function __construct($timestamp, $increment, $localTimezone, $utcTimezone) {
$this->timestamp = $timestamp;
$this->increment = $increment;
$this->localTimezone = $localTimezone;
$this->utcTimezone = $utcTimezone;
}
public function __toString() {
return "Timestamp: " . $this->timestamp . ", Increment: " . $this->increment . ", Local Timezone: " . $this->localTimezone . ", UTC Timezone: " . $this->utcTimezone;
}
}
위 코드에서 CustomTimestamp 클래스는 MongoDBBSONTimestampInterface를 구현하고, __toString 메서드를 오버라이딩하여 Timestamp 객체를 문자열로 변환합니다.
2025-08-07 08:52