note 120206 deleted from functions.returning-values by cmb

From: Date: Thu, 13 Aug 2020 09:31:30 +0000
Subject: note 120206 deleted from functions.returning-values by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214950@lists.php.net to get a copy of this message
Note Submitter: ortreum ---- I like this method of concatinating methods by returning $this. It makes my code more readable. If the returned value is not an object it will fail and you find mistakes easier. <?php class Dummy { private $result; function __construct() { $this->result = $this ->setStuff('abc') ->generateResult() ; } function setStuff($value) { // do something return $this; } function generateResult() { return ['the result']; } function getResult() { return $this->result; } } ?>

« previous php.notes (#214950) next »