$protected_property_name = '_'.$name;
if(property_exists($this, $protected_property_name)){
return $this->$protected_property_name;
}
私はオブジェクト指向プログラミングのチュートリアルに従っていますが、インストラクターは私が持っていない新しいコード構造を思いついたなぜ彼がそれをしたのかについての明確な説明なしに、前に見た。 if(ステートメント)内に気付いた場合 $ this-> $ protected_property_nameステートメントは$ thisと$ protected_property_nameの2つの$記号を持っていますが、通常はドル記号を付けずに $ this-> protected_property_nameでなければなりませんprotected_property_name変数に追加します。 protected_property_name変数から$記号を削除しようとしたときにエラーが発生しました。完全なコードは次のようになります
class Addrress{
protected $_postal_code;
function __get($name){
if(!$this->_postal_code){
$this->_postal_code = $this->_postal_code_guess();
}
//Attempt to return protected property by name
$protected_property_name = '_'.$name;
if(property_exists($this, $protected_property_name)){
return $this->$protected_property_name;
}
//Unable to access property; trigger error.
trigger_error('Undefined property via __get:() '. $name);
return NULL;
}
}
'ます$ this-> property_name'単にクラスのプロパティを指します。 '$ this-> $ property_name'は「可変プロパティ」です。件名のマニュアルは次のとおりです。http://php.net/manual/en/language.variables.variable.php –
私はまだ混乱していますが、あなたは明確にしてください。私はマニュアルを読むが、それでも意味をなさない。 – Salim