Shawn McKenzie wrote:

Maybe a dumb question, but as good coding practice, should all functions
return something even if they don't need to???

Example:

function do_it()
{
   echo "hi";
}

--or--

function do_it()
{
   return echo "hi";
}

Also, if they do other things but really don't return anything, should they
return true maybe???

Like all things, it depends on what the function is doing.


If the function is already displaying output, then there is no need to return a particular value, although a habit from my C++ days (no doubt caused by the compiler warning: not all paths return value) is to add a simple return; at the end, to ensure that the function will return.

If the function is setting values, a good thing to do is to return the result (which will be a true or false) so you can see if the value is being set or not.

Classes that use PEAR return objects (usually of PEAR:Error) if there was an error in the class.

If all your function is doing is printing output, no need to return anything, since the success of the function will be apparent once you call it.

FWIW,
--
Burhan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to