Method definition
Example of a function definition:
<?php
function someFunction($arg1, $arg2 = '') {
if (expr) {
statement;
}
return $var;
}
?> <?phpfunction someFunction($arg1, $arg2 = '') {if (expr) {statement;}return $var;}?>
Parameters with a default value, should be placed last in function definition. Try to make your functions return something, at least true or false - so it can be determined whether the function call was successful.
<?php
function connection(&$dns, $persistent = false) {
if (is_array($dns)) {
$dnsInfo = &$dns;
} else {
$dnsInfo = BD::parseDNS($dns);
}
if (!($dnsInfo) || !($dnsInfo['phpType'])) {
return $this->addError();
}
return true;
}
?> <?phpfunction connection(&$dns, $persistent = false) {if (is_array($dns)) {$dnsInfo = &$dns;} else {$dnsInfo = BD::parseDNS($dns);}if (!($dnsInfo) || !($dnsInfo['phpType'])) {return $this->addError();}return true;}?>
There are spaces on both side of the equals sign.


























