RE: Multiple return statements in a function.

From: Date: Fri, 24 Apr 2009 01:57:14 +0000
Subject: RE: Multiple return statements in a function.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-291903@lists.php.net to get a copy of this message
Well, the latter method is generally easier to understand later. Most programming style books preach this method, and it's the one that most of my previous employers use. Cheers... -----Original Message----- From: Peter van der Does [mailto:pvanderdoes@gmail.com] Sent: Thursday, April 23, 2009 8:13 AM To: php-general@lists.php.net Subject: Multiple return statements in a function. I tend to put my return value in a variable and at the end of the function I have 1 return statement. I have seen others doing returns in the middle of the function. Example how I do it: function check($a) { $return=''; if ( is_array( $a ) ) { $return='Array'; } else { $return='Not Array'; } return $return; } Example of the other method: function check($a) { if ( is_array( $a ) ) { return ('Array'); } else { return ('Not Array'); } } What is your take? And is there any benefit to either method? -- Peter van der Does GPG key: E77E8E98 Blog: http://blog.avirtualhome.com Forums: http://forums.avirtualhome.com Jabber ID: pvanderdoes@gmail.com GetDeb Package Builder http://www.getdeb.net - Software you want for Ubuntu

« previous php.general (#291903) next »