Page 1 of 1

Question about function returns

Posted: Wed Jul 18, 2007 8:40 pm
by TomTraubert
If I have the following code:

Code: Select all

function myFunction() {
    $myDbObject = new DbObject;
    
    $myDbObject->dbOpen();
    $records = $myDbOject->getRecords();

    if (mysql_num_rows($records) > 0) {
        echo ("success!");
        return TRUE;
    }
							
    $myDbObject->dbClose();
}
Does the dbClose method of myObject get fired before myFunction sends control back to the calling routine? Or does return TRUE; happen after the entire function is handled?

Advice is appreciated!

-- Tom

Posted: Wed Jul 18, 2007 8:42 pm
by Begby
As soon as a return is executed then the function ends, no more code is executed afterwards. In this case if your IF statement evaluated to true, then the function would return true and dbClose() would never be executed.

Posted: Thu Jul 19, 2007 11:15 am
by TomTraubert
Thanks Begby. Guess I'll add a few more lines of code to that function, then. :)