Access Keys:
Skip to content (Access Key - 0)
Home (Access Key - 1)
All spaces... (Access Key - 3)
Log in (Access Key - 5)
Sign up (Access Key - 6)
Development

Mambo Manual is part of the documentation project for the Mambo open source content management system

Toggle Sidebar

Function Definitions


Function declarations follow the "one true brace" convention:

<?php

function fooFunction( $arg1, $arg2 = '' ){
    if (condition)
{
        statement;
    }
    return $val;
}
?>

Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate.
Here is a slightly longer example:

<?php
function connect( &$dsn, $persistent = false ){
    if (is_array( $dsn ))
{
        $dsninfo = &$dsn;
    }
 else {
        $dsninfo = DB::parseDSN( $dsn );
    }
    if (!$dsninfo || !$dsninfo'phptype') {
        return $this->raiseError();
    }
    return true;
}
?>

The opening brace is written on the same line as the function declaration. The closing brace is always written on its own line. Any content within the braces should be indented.

Next: Comments

Toggle Sidebar
Space Navigation
Added by Lynne Pope on 28 Dec, 2007 04:22, last edited by Lynne Pope on 28 Dec, 2007 04:22

Adaptavist Theme Builder Powered by Atlassian Confluence
Free theme builder license