Page 1 of 1
Returning Function Values
Posted: Fri Dec 01, 2006 11:01 am
by snowrhythm
i've heard that a function is always supposed to return something or else it's technically a subroutine.
what if i'm using a function in a class (a method) and it's just setting a member variable and not
really returning anything, am i supposed to
or should I return that member
variable? it seems redundant to return a variable that can be used throughout the class once the function
has been called.
Posted: Fri Dec 01, 2006 11:04 am
by Jenk
no, a function does not have to return a value.
Posted: Fri Dec 01, 2006 11:11 am
by Burrito
a function can 'return' void.
in other languages you must explicitly define this such as:
Code: Select all
public void someMethod()
{
//..
}
// vs
public string someMethod(string someVar)
{
return someVar + " some appended string";
}
but with php such definitions are NOT required.
Posted: Fri Dec 01, 2006 11:15 am
by John Cartwright
if no return is specified, the function will return null regardless.
Posted: Fri Dec 01, 2006 11:25 am
by Luke
Posted: Mon Dec 18, 2006 10:50 am
by raghavan20
i would say it does not really matter; if you want to return, return something else do not return.
eventhough technically one which returns is a function and which does not is a subroutine; it also depends on how programming languages consider it.
but it is important to return proper values
1. like making decisions: return TRUE or FALSE
2. if object, result set or some value is epcted: return value if available else return NULL
but there is no point in keep returning NULL if return is not expected by calling function.