4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

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


![DQmPiKcYtB7kqiL7JBjL6JuybPbUPxNvxTAkFarMCAP5xZK_1680x8400.jpeg](https://steemitimages.com/DQmUq4Q2fGmX1eNirYvuqxfwwmkX8oQG4s5FQympmnXnHq5/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

22 upvotes 1 downvotes $0.03

Replies (5)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: