Short Hint for Coding : Best-Practice : Implementation a constant Property on PHP




DQmPiKcYtB7kqiL7JBjL6JuybPbUPxNvxTAkFarMCAP5xZK_1680x8400.jpeg


Implementation a constant Property on PHP

PHP-Klassen bieten das Konzept von Konstantenzuweisungen nicht über Klassenmethoden an. Es gibt aber Wege,
ein Final auf Properties zu erzeugen.

Die Umsetzung in PHP ist wie folgt möglich:

Beispiel:


  /**
     * @param string $pass
     *
     * @return $this
     */
    public function setfinal_pass( $pass ){
        ( $this -> pass !== NULL ) ?:$this -> pass = $pass;
        return $this;
    }

Die setfinal_pass-Methode prüft, ob der Wert von pass schon übergeben wurde.
Im Erfolgsfall passiert einfach Nichts. Wenn der Wert von pass noch NULL besitzt
kann pass parametrisiert werden.
NULL selber steht aber dann nicht mehr als WERT zur Verfügung.



#webdevelopment #code #coding #dev #development #programming
#codedesign #codereview #cleancode #steemit #utopian-io
#technology #science #deutsch #deutschland #german #germany
#orginal #originalworks #diy #php #php5 #php7 #oop #ood
#webserver #webdev #practice #mail #www #web #final #patterns


rect4138.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center