Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ 10 Codes of good practice PHP     - Quickly build and install Linux KVM system (Linux)

- How to use Linux iptables tool for network sharing (Linux)

- Using a proxy method under Linux terminal (Linux)

- Install NetBeans IDE 8.0 on Ubuntu, Linux Mint, Elementary OS, and Debian (Linux)

- How to fix the Ubuntu Error script returned error exit status 1 (Linux)

- Python control multi-process and multi-threaded concurrency (Programming)

- ethtool implementation framework and application in Linux (Linux)

- CentOS / Linux kernel upgrade (Linux)

- ARM runtime environment built from scratch using QEMU emulator (Linux)

- Ubuntu and derivative system users how to install Pinta 1.5 (Linux)

- mysqldump issue a note (Database)

- Tmux Crash Course: Tips and adjustment (Linux)

- Why do I prefer Git (Linux)

- Ubuntu 14.04 Configuring cuda-convnet (Linux)

- About Hibernate cache, you want the latest data have trouble even session.clear (Database)

- About DataGuard three protected mode test (Database)

- Using PPA to install the lightweight theme software HotShots 2.1.0 under Ubuntu (Linux)

- AngularJS application unit testing started (Programming)

- Jigsaw project will solve the problem of Java JAR hell Mody (Programming)

- Oracle through the alarm log view and inspect the main library, physical and snapshot standby database (Database)

  10 Codes of good practice PHP
  Add Date : 2017-01-08      
  PHP is known as dirty but quick programming language. Although in other programming languages, user opinion, PHP program is not simple and beautiful, but we can pass some good programming habits, but also allow PHP code looks more comfortable and elegant. What are the methods? Below each of said next.

1. Planning Code Structure

Excellent PHP code should have a clear structure. PHP object-oriented features allows programmers to application into a function or method. If the code is obscure, you can also add notes, make the code function at a glance. The server should try coding rule front-end code (HTML / CSS / JavaScript) and separate application, or you can build your application using PHP framework that follows the MVC pattern.

2. Uniform Coding Style

Excellent PHP code should have a unified style. For example, variables, and functions to develop uniform naming convention for the cyclic tasks (such as database access, error handling) to develop uniform standards of access, or to maintain a regular code indentation, these coding practices can let others read the code more easy.

3. Portability

Excellent PHP code should be portable. PHP programmers should learn to use existing features (such as magic quotes and short labels, etc.), you should understand the product needs to adapt to the characteristics of PHP, PHP code written guarantee portability and cross-platform.

4. Security Code

Excellent PHP code should have security. PHP5 has excellent features and flexibility, but security applications are often in the hands of programmers. As a professional PHP developers should have some understanding of security vulnerabilities, common security vulnerabilities cross-site scripting attacks (XSS), cross-site request forgery (CSRF), code injection vulnerabilities and character encoding loopholes. Use PHP specific features and functions (such as mysql_real_escape_string, etc.) can help programmers write secure code.

5. Add comments

Code comments are an important part of the code that explains the purpose of the function is, and this will provide a very useful comments in the code to help future maintenance.

6. Avoid shorthand tag

Should use the full start flag is not recommended to use shorthand starting mark.

7. Use single quotes instead of double quotes

Because PHP will double quotes variable content search, in order to avoid the impact of this search brings performance, programmers should use single-quoted strings.

8. escape output

ENT_QUOTES parameters should be used in the htmlspecialchars function, to ensure that the single quotation mark ( ') can also be escaped. Although there is no requirement to do so, but this is a good habit.

9. Use a comma separated string output

String concatenation operator (.) Can be a single string to echo statements output, compared with a comma can echo statement outputs a string, which PHP is a performance improvement.

10. Check the value before the transfer output

It should be recalled pass values output before checking $ _GET [ 'query'] of. Use isset function or empty function can check whether the value of the variable is empty.
- Nginx + ownCloud + PHP + MySQL to build personal private cloud under CentOS7 (Server)
- Git common skills (Linux)
- Keepalived + HAProxy high availability load balancing (Server)
- How to write a new Git protocol (Linux)
- JDK tools jstat (Linux)
- Linux operating system log system (Linux)
- Learning MySQL data types (Database)
- Oracle data files deleted recover after physical (Database)
- ActionContext and ServletActionContext Summary (Programming)
- Gitblit adopted Ticket collaborative development model (Linux)
- Linux System Administrator common interview questions and answers 30 (Linux)
- Oracle 11g users to create, authorize and import dmp file (Database)
- A detailed introduction to the Hadoop ecosystem (Server)
- Python-- for anomalies and reflection of objects articles (Programming)
- CentOS 7 install Hadoop-cdh-2.5 on Mesos (Server)
- Linux user login and IP restrictions (Linux)
- Why you should choose Python Programming (Programming)
- Linux supports serial output method (Linux)
- DB2 Version SQLJ to access Oracle Server (Database)
- Fatal NI connect error 12170 error in Alert Log (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.