RE: [PHP] Return or not to return, that is the question

From: Date: Wed, 30 May 2007 12:56:16 +0000
Subject: RE: [PHP] Return or not to return, that is the question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-255803@lists.php.net to get a copy of this message
[snip] All depends on the function. function someFunc(){ $this->counter++; if($this->counter > 100) $this->counter = 0; } Something that simple wont need a return at all. [/snip] Classically this would need a return, because $this->counter is going to be less than 100 most of the time, and you may want to return the value at some point. Here is the thing (it is akin to all of the holy wars on brackets, etc), the use of return has been pounded into old-schoolers heads for a long time, regardless of the Boolean or value returned. It is good style and it introduces consistency. As far as it being an extra line of code? So be it! We're not in the day and age where we had to count CPU cycles! If anyone is designing PHP applications with that level of granularity they have entered into an amazingly pedantic process for which PHP is not well suited.

« previous php.general (#255803) next »