* 업데이트 예PHP에 대한 자세한 내용
일부 기사와 php.net을 읽었습니다. 그러나 'this'예제에서 $ this를 이해하는 데 여전히 문제가 있습니다. 기본 용도가 무엇인지 이해합니다.
내가 마지막에이 기능을 가지고 있다고 가정 해 보겠습니다. return $ this; // 아무것도 $ this 뒤에 온다.
$ this (끝 부분에있는)는 무엇을 참조 할까? 은 어떻게 $이이
public function check($source, $items = array()){
foreach ($items as $item => $rules) {
foreach($rules as $rule => $rule_value){
$value = trim($source[$item]);
$item = escape($item);
if($rule === 'required' && empty($value)) {
$this->addError("{$item} is required");
} else if(!empty($value)) {
switch($rule) {
case 'min':
if(strlen($value) < $rule_value) {
$this->addError("{$item} must be a minimum of {$rule_value} characters");
}
break;
case 'max':
if(strlen($value) > $rule_value) {
$this->addError("{$item} must be a maximum of {$rule_value} characters");
}
break;
}
}
}
}
if(empty($this->_errors)) {
$this->_passed= true;
}
return $this;
}
*이 코드는 레지스터 및 검증 클래스의 일부입니다 무엇 에코 - 보내고/확인할 수 있습니다. 그러나 요점은 여전히 결국 $ this가 가리키는 것입니다. 감사합니다
'var_dump ($ this); ' – RST
$ 이것은 객체 자체를 참조합니다. 여기를 읽어보십시오. http://stackoverflow.com/questions/1523479/what-does-the-variable-this-mean-in-php – pbaldauf
PHP 코드 패드를 작성하는 방법에 대해 (지금 삭제 된 질문에) 물었습니다. [여기에 하나 있습니다] (https://github.com/Viper-7/Deployable-PHP-Codepad). – halfer