
MongoDBBSONTimestampInterface의 __toString 메서드는 객체의 문자열 표현을 반환하는 역할을 합니다.
예를 들어, Timestamp 객체를 문자열로 변환할 때 사용됩니다.
이 메서드를 오버라이딩하는 방법은 다음과 같습니다.
#hostingforum.kr
php
class CustomTimestamp implements MongoDBBSONTimestampInterface {
// ...
public function __toString(): string {
return 'Custom Timestamp: ' . $this->getTimestamp();
}
}
이 코드에서는 CustomTimestamp 클래스가 MongoDBBSONTimestampInterface를 구현하고, __toString 메서드를 오버라이딩했습니다. 이 메서드는 Timestamp 객체를 문자열로 변환하고, 'Custom Timestamp: '를 추가합니다.
2025-03-26 01:42