I was just looking at this code and i don't understand what RETURN TRUE does or what the point of it is? Can someone please explain?
class Elephpant {
public $colour;
public function dance() {
echo "elephpant dances!\n";
return true;
}
}
Thankyou in advance ;-)
Sometimes a method/function returns a boolean value to indicate if the operation was succesfull. In the given example it always returns "TRUE".
To check if a function returns true , call the function and check if its return value is equal to true , e.g. if (func() === true) . If the function's return value is equal to true the condition will be satisfied and the if block will run.
return 0 in the main function means that the program executed successfully. return 1 in the main function means that the program does not execute successfully and there is some error. return 0 means that the user-defined function is returning false. return 1 means that the user-defined function is returning true.
returning true or false indicates that whether execution should continue or stop right there. So just an example <input type="button" onclick="return func();" /> Now if func() is defined like this function func() { // do something return false; }
It returns the boolean TRUE to whatever called dance(). That's all.
You would have to look at the consuming code to see if it makes something from it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With