A függvénydefiníciók a "one true brace" megállapodást követik:
<?php
function fooFunction($parameter1, $parameter2 = '')
{
if (feltetel) {
utasitas;
}
return $ertek;
}
?>
|
A default értékekkel rendelkező paraméterek a paraméterlista
végére kerülnek. Mindig próbáljunk meg jelentéssel bíró
értékkel visszatérni egy függvényből, amennyiben lehetséges.
Egy hosszabb példa:
<?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;
}
?>
|
|
Függvényhívások (Previous)
|
(Next) Megjegyzések (kommentek)
|
|
|
Download Documentation
|
Last updated: Sun, 01 Jul 2007 |
|
Do you think that something on this page is wrong? Please file a bug report or add a note.
|
| User Notes: |
Note by: Mike
Note to previous post: the Allman style is not only used for functions but also for class definitions.
Note by: pear at alan hogan dot com
Allman style is defined here for those unfamiliar with it:
http://en.wikipedia.org/wiki/Indent_style
Please note that the PEAR coding standards *do not* follow Allman style for *control structures*, only for functions.
Note by: pear at alan hogan dot com
Again according to Wikipedia, it would seem that PEAR, in fact, advocates K&R style:
function foo ()
{
//do stuff();
}
while (true) {
if (true ) {
//x..
}
}
It should be noted that both Allman and K&R agree on how to format function definitions.
|
|