Table of Contents
3.永远不要相信你的用户——Dave Child
4.关注缓存——Ben Balbo
5.通过IDE,模板或者代码片段加快开发速度——Chad Kieffer
6.使用PHP的过滤函数——Joey Sochacki
7.使用PHP框架——Josh Sharp
9.使用多线程——Jack D. Herrington
10.马上开起错误报告——David Cummings
Home php教程 php手册 PHP大师指点:优秀的PHP代码怎么来?

PHP大师指点:优秀的PHP代码怎么来?

Jun 13, 2016 am 11:39 AM
http php code excellent how of

原文:http://nettuts.com/articles/10-principles-of-the-php-masters/

随着PHP的流行,你可以随便找一段代码来实现想要的功能,但怎样的代码才算得上是优秀的代码呢?此时,我们需要大师们的指点

1.只有在需要的时候才使用PHP——Rasmus Lerdorf(PHP创始人)


不要什么事都让PHP来做,PHP只是一种工具,每一种语言都会有自身的限制
当不能用PHP来解决时,不要害怕使用其他的语言

2.尽可能地在MySQL里多用表——Matt Mullenweg(wordpress创始人)



3.永远不要相信你的用户——Dave Child

Dave Child是Added Bytes的创作者(前身:www.ilovejackdaniels.com)。为好几门语言创建了cheat sheet(入门笔记)

Dave写了几篇关于PHP的文章,最后他的建议是这样的:

要有绝对偏执的心态。如果不想自己的网站老是受到攻击,或者经常出现各种问题,那就假设每一个用户都是恶意的,而你将长期处于戒备状态,这会使你的网站更加安全

4.关注缓存——Ben Balbo

Ben Balbo为sitepoint写文章,他是PHP讨论组和开源组的负责人,建议多花点心思在PHP缓存上面。

对于那些变动不大的网站,比如blog,可以通过设置缓存,来取得明显的效果。如果是稍微复杂一点的网站,比如购物,对缓存的设置就有更高的要求,不过通常效果都很不错。其实从本质上来说,缓存就是存储那些经常被用到,但是变化不大的内容

5.通过IDE,模板或者代码片段加快开发速度——Chad Kieffer



6.使用PHP的过滤函数——Joey Sochacki

需要安装filter插件,不具普遍性,所以忽略

7.使用PHP框架——Josh Sharp

使用框架可以节省时间,同时排除错误,因为PHP本身实在是太容易学了。正是因为PHP没有太严格的限制,所以很容易写出不规范的代码,解决办法就是使用框架。可以看一下他的这篇文章“使用框架的好处”

8.不要使用PHP框架——Rasmus Lerdorf

跟上面对立的观点,最大的原因就在于执行效率。

Drupalcon 2008大会上,Rasmus通过几个“hello world”对比了纯PHP和几个框架的执行效率,结果证明PHP框架的执行效率远低于纯PHP代码

[如果要使用一个php框架的话,Rasmus推荐CodeIgniter(我推荐Kohana,哈哈),因为它“最不像一个框架”]

9.使用多线程——Jack D. Herrington


10.马上开起错误报告——David Cummings

我最想对php开发人员说的是:把错误报告的级别调到最高。详见“2 quick php tips”,从长远的角度来说,这节省了不少时间。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How to identify genuine and fake shoe boxes of Nike shoes (master one trick to easily identify them) How to identify genuine and fake shoe boxes of Nike shoes (master one trick to easily identify them) Sep 02, 2024 pm 04:11 PM

As a world-renowned sports brand, Nike's shoes have attracted much attention. However, there are also a large number of counterfeit products on the market, including fake Nike shoe boxes. Distinguishing genuine shoe boxes from fake ones is crucial to protecting the rights and interests of consumers. This article will provide you with some simple and effective methods to help you distinguish between real and fake shoe boxes. 1: Outer packaging title By observing the outer packaging of Nike shoe boxes, you can find many subtle differences. Genuine Nike shoe boxes usually have high-quality paper materials that are smooth to the touch and have no obvious pungent smell. The fonts and logos on authentic shoe boxes are usually clear and detailed, and there are no blurs or color inconsistencies. 2: LOGO hot stamping title. The LOGO on Nike shoe boxes is usually hot stamping. The hot stamping part on the genuine shoe box will show

See all articles