{4804} - 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)) {
$dns_info = &$dns;
} else {
$dns_info = BD::parseDNS($dns);
}
if (!($dns_info) || !($dns_info['phpType'])) {
return $this->addError();
}
return true;
}
?> <?phpfunction connection(&$dns, $persistent = false) {if (is_array($dns)) {$dns_info = &$dns;} else {$dns_info = BD::parseDNS($dns);}if (!($dns_info) || !($dns_info['phpType'])) {return $this->addError();}return true;}?>
There are spaces on both side of the equals sign.
{5021} - 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.
Differences
| Lines: 11-24 | Lines: 11-24 | ||
| <p>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. </p> | <p>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. </p> | ||
| <pre><?php | <pre><?php | ||
| function connection(&$dns, $persistent = false) { | function connection(&$dns, $persistent = false) { | ||
| if (is_array($dns)) { | if (is_array($dns)) { | ||
| - | $dnsInfo = &$dns; | + | $dns_info = &$dns; |
| } else { | } else { | ||
| - | $dnsInfo = BD::parseDNS($dns); | + | $dns_info = BD::parseDNS($dns); |
| } | } | ||
| - | if (!($dnsInfo) || !($dnsInfo['phpType'])) { | + | if (!($dns_info) || !($dns_info['phpType'])) { |
| return $this->addError(); | return $this->addError(); | ||
| } | } | ||
| return true; | return true; | ||
| } | } | ||


























