trafficmonitor/app/DTOs/CommonDTO.php

22 lines
625 B
PHP

<?php
namespace App\DTOs;
abstract class CommonDTO
{
public function __construct() {}
public function __get(string $name)
{
// 1. 속성이 클래스에 실제로 존재하는지 확인
if (property_exists($this, $name)) {
// 2. 속성이 존재하면 값을 반환 (PHP 7.4 이상의 타입 속성 덕분에 null 병합 연산자 사용 불필요)
return $this->{$name};
}
// 3. 속성이 존재하지 않으면 오류 발생 (일반적인 Entity/DTO 접근 방식)
throw new \BadMethodCallException(
"Undefined property or method: " . static::class . "::{$name}"
);
}
}