Home >Backend Development >PHP Tutorial >PHP coding standards (21)_PHP tutorial
8.3 Function
The method name is a verb, using mixed case. The first letter of the first word is lowercase, and the first letter of subsequent words is capitalized.
function run();
function runFast();
function getBackground();
Usually each method performs an action, so its naming should clearly indicate what it does: use checkForErrors() instead of errorCheck(), and use dumpDataToFile() instead of dataFile(). Doing so also makes functions and data more distinguishable objects.
Sometimes suffixes are useful:
Max - meaning the maximum value that can be assigned to an entity.
Cnt - The current value of a running count variable.
Key - key value.
For example: retryMax represents the maximum number of retries, and retryCnt represents the current number of retries.
Sometimes prefixes are useful:
is - meaning to ask a question about something. Whenever people see Is they know it's a problem.
get - means to get a value.
set - means setting a value
For example: isHitRetryLimit