나는 잘 돌아 다니며이 문제에 대한 답을 찾지 못하는 것 같습니다.메서드에서 보호 된 변수 선언하기
기본적으로 변수를 선언 할 때 _call 메서드를 사용하여 동적으로 get 및 set 메서드를 생성하지만 PHP 기본값은 public입니다. 어쨌든 클래스 내에서 변수를 보호 된 것으로 선언 할 수 있습니까?
function __call($method, $arguments) {
$prefix = strtolower(substr($method, 0, 3));
$property = strtolower(substr($method, 3));
if (empty($prefix) || empty($property)) {
return;
}
if ($prefix == "get" && isset($this->$property)) {
return $this->$property;
}
if ($prefix == "set") {
$this->$property = $arguments[0];
}
}
왜, 왜 __get 및 __set 대신 __call을 사용하고 있습니까? –
그냥 쉽게 보였습니다. 여기에서 복사했습니다. http://onlamp.com/pub/a/php/2005/06/16/overloading.html –