채택완료
php에서 이런 클래스 정의 시, 이걸 활용해 값을 출력하려면?
Copy
<?php
class IPv4Address implements Stringable {
public function __construct(private string $oct1, private string $oct2, private string $oct3, private string $oct4) {
}
public function __toString(): string {
return "$this->oct1.$this->oct2.$this->oct3.$this->oct4";
}
}
?>
https://www.php.net/manual/en/class.stringable.php
활용 방법 예제 좀 부탁드려요.
답변 2개 / 댓글 3개
채택된 답변
+20 포인트
$tmp1= 'abc';
$tmp2= new IPv4Address('123', '234', '42', '9');
$tmp3= $tmp1 . $tmp2; // 이런 것이 가능하죠.
답변에 대한 댓글 3개
답변을 작성하려면 로그인이 필요합니다.