私はクラスを再フォーマットしているところです(以下を参照)-クラスですべてを同じ可視性で設定するのを間違えたと思いますが、プロパティは実際にはプライベートであり、ゲッター/セッターはほとんどの場合パブリックである必要があります。
プロパティを取得するには、$ path-> propertynameを実行しますが、setter/getterを使用する方が実用的であることに気付きました。ゲッターを実装する場合、プロパティごとに1つ作成する必要がありますか、それともクラス全体に1つ作成できますか?たとえば、コントローラー名を取得したいとします...
public function getController( ) {
return $this->controller;
}
そして、それはコントローラーのプライベートプロパティを返しますか?より一般的なゲッター/セッター、または私のために取得して設定するハイブリッドメソッドを使用することは一般的ですか?
クラス構造は次のとおりです(プロパティ/メソッドのみ):
class urlParser {
public static $url = '';
public static $controller = '';
public static $baseController = '';
public static $urls = '';
public static $template = '';
public static $captures = '';
public static $contentXML = '';
function __construct( $urls ) {
$this->urls = $urls;
$this->baseController = $urls['default'];
$this->get_url();
}
public function get_url() {
// sets following properties:
// url, template, controller, contentXML, baseController
}
}