Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does RETURN TRUE do in a php function?

Tags:

php

cakephp

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 ;-)

like image 762
Imran Avatar asked Apr 14 '10 10:04

Imran


People also ask

What is return true in PHP?

Sometimes a method/function returns a boolean value to indicate if the operation was succesfull. In the given example it always returns "TRUE".

What is the use of return 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.

Is return true the same as return 0?

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.

What is return true and return false?

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; }


1 Answers

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.

like image 191
Gordon Avatar answered Oct 05 '22 22:10

Gordon