Write first: Legibility of code, which I consider very important, is valued by the team but not always implemented. Although object-oriented has become the norm, procedural writing is still common in the PHP world and among the phpers I’ve encountered. Maintenance costs also vary. The following is my work in some summary and ideas, if there is uncomfortable to see, change a comfortable posture.

named


1. Decide whether to use a verb or a noun; 2. Make it specific; 3

eg1. userName VS userAttribute eg2. setName VS manageName eg3. GetUserName VS getUserNameByUid

annotation











Code life cycle


$userLogObjectId = "string";
$userLogForCache= array(...) ;$userLogForStorage= array(...) ;if(! createUserLogForCache($userLogObjectId.$userLogForCache)) return false;
if(! createUserLogForStorage($userLogObjectId.$userLogForStorage)) return false;
Copy the code
vs
Copy the code
$userLogObjectId = "string";
$userLogForCache= array(...) ;if(! createUserLogForCache($userLogObjectId.$userLogForCache)) return false;
$userLogForStorage= array(...) ;if(! createUserLogForStorage($userLogObjectId.$userLogForStorage)) return false;
Copy the code

2. Method calls follow as closely as possible

public function setInputRules() {... } publicfunction getInputValues() {... } publicfunction main() {$this->setInputRules();
    $this->getInputValues();
}
Copy the code
vs
Copy the code
public function main() {$this->setInputRules();
    $this->getInputValues();
}
private function setInputRules() {... } privatefunction getInputValues() {... }Copy the code

4. Use constants carefully :const vs define

Access permissions








Relationships between classes

















Design patterns








test





Write at the back: Comfortable to look at, but in fact, the code is constantly optimized refactoring performance. Is the embodiment of code excellence. I’ve never seen anyone write code all at once without making changes. Looking forward to! Practice makes perfect, I hope I can also through their own summary, inspire themselves, to become a diligent person!