Skip to content

更新到2020年4月26日29f8049版本,更新于2020.9.4 #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: gh-pages
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Pull requests are a great way to add new content to PHP The Right Way, as well
as updating any browser issues or other style changes. Pretty much any sort of
change is accepted if seen as constructive.

Adhering to the following this process is the best way to get your work
Adhering to the following process is the best way to get your work
included in the project:

1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork,
Expand Down Expand Up @@ -74,7 +74,7 @@ included in the project:
5. Commit your changes in logical chunks. Please adhere to these [git commit
message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
or your content is unlikely be merged into the main project. Use Git's
[interactive rebase](https://help.github.com/articles/interactive-rebase)
[interactive rebase](https://help.github.com/articles/about-git--rebase/)
feature to tidy up your commits before making them public.

6. Locally merge (or rebase) the upstream development branch into your topic branch:
Expand Down Expand Up @@ -115,5 +115,5 @@ All content is completely free now, and always will be.
2. Use four (4) spaces to indent text; do not use tabs
3. Wrap all text to 120 characters
4. Code samples should adhere to PSR-1 or higher
5. Use [GitHub Flavored Markdown](http://github.github.com/github-flavored-markdown/) for all content
5. Use [GitHub Flavored Markdown](https://github.github.com/gfm/) for all content
6. Use language agnostic urls when referring to external websites such as the [php.net](http://php.net/urlhowto.php) manual
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* [한국어판](http://modernpug.github.io/php-the-right-way)
* [日本語](http://ja.phptherightway.com)
* [简体中文](https://laravel-china.github.io/php-the-right-way/)
* [繁體中文](http://laravel-taiwan.github.io/php-the-right-way)
* [繁體中文](https://laravel-taiwan.github.io/php-the-right-way)

### 翻译

Expand Down
14 changes: 4 additions & 10 deletions _includes/welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@ _PHP: The Right Way_ 被翻译为以下版本:
* [한국어판](http://modernpug.github.io/php-the-right-way)
* [日本語](http://ja.phptherightway.com)
* [简体中文](https://laravel-china.github.io/php-the-right-way/)
* [繁體中文](http://laravel-taiwan.github.io/php-the-right-way)
* [繁體中文](https://laravel-taiwan.github.io/php-the-right-way)

## 书本

最新版本的 _PHP 之道_ 包含 PDF, EPUB 和 MOBI 版本,可以在 [Leanpub][1] 上购买。

## 如何参与 {#how-to-contribute}

帮助我们让本网站作为 PHP 新手的最佳资源![在 GitHub 上贡献][2]

## 推广 {#spread-the-word}

_PHP: 您可以在网站上放置 PHP之道 的横幅来支持我们,让 PHP 的新人知道哪里可以获取到好的资料!

[广告横幅][3]
帮助我们让本网站作为 PHP 新手的最佳资源![在 GitHub 上贡献 【English】][2] [【中文】][3]

[1]: https://leanpub.com/phptherightway
[2]: https://github.com/summerblue/php-the-right-way/tree/gh-pages
[3]: /banners.html
[2]: https://github.com/codeguy/php-the-right-way/tree/gh-pages
[3]: https://github.com/laravel-china/php-the-right-way/tree/gh-pages
4 changes: 2 additions & 2 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<title>{% if page.title %}{{ page.title }} - {% endif %} PHP 之道 | PHP The Right Way 中文版</title>
<meta name="description" content="{{ page.description }}"/>
<meta name="robots" content="index,follow,archive"/>
<meta property="og:image:url" content="http://www.phptherightway.com/images/og-image.png"/>
<meta property="og:image:url" content="https://www.phptherightway.com/images/og-image.png"/>
<meta property="og:image:width" content="1024"/>
<meta property="og:image:height" content="640"/>
<meta property="og:title" content="PHP: The Right Way"/>
<meta property="og:description" content="An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative PHP tutorials around the Web"/>
<meta property="og:url" content="http://www.phptherightway.com"/>
<meta property="og:url" content="https://www.phptherightway.com"/>
<meta property="og:site_name" content="PHP: The Right Way"/>
<meta property="og:type" content="website"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
Expand Down
4 changes: 2 additions & 2 deletions _layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<title>{% if page.title %}{{ page.title }} - {% endif %} PHP 之道 | PHP The Right Way 中文版</title>
<meta name="description" content="{{ page.description }}"/>
<meta name="robots" content="index,follow,archive"/>
<meta property="og:image:url" content="http://www.phptherightway.com/images/og-image.png"/>
<meta property="og:image:url" content="https://www.phptherightway.com/images/og-image.png"/>
<meta property="og:image:width" content="1024"/>
<meta property="og:image:height" content="640"/>
<meta property="og:title" content="PHP: The Right Way"/>
<meta property="og:description" content="An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative PHP tutorials around the Web"/>
<meta property="og:url" content="http://www.phptherightway.com"/>
<meta property="og:url" content="https://www.phptherightway.com"/>
<meta property="og:site_name" content="PHP: The Right Way"/>
<meta property="og:type" content="website"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
Expand Down
10 changes: 5 additions & 5 deletions _posts/01-02-01-Use-the-Current-Stable-Version.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
title: 使用当前稳定版本 (7.1)
title: 使用当前稳定版本 (7.4)
isChild: true
anchor: use_the_current_stable_version
---

## 使用当前稳定版本 (7.1) {#use_the_current_stable_version_title}
## 使用当前稳定版本 (7.4) {#use_the_current_stable_version_title}

如果你刚开始学习 PHP,请使用最新的稳定版本 [PHP 7.1][php-release]。PHP 7.1 非常新,相较于 5.x 版本增加了强大的 [新特性](#language_highlights)。PHP 引擎大部分被重写,PHP 的运行速度已经远远超越过去。
如果你刚开始学习 PHP,请使用最新的稳定版本 [PHP 7.4][php-release]。PHP 7.x 非常新,相较于 5.x 版本增加了强大的 [新特性](#language_highlights)。PHP 引擎大部分被重写,PHP 的运行速度已经远远超越过去。

在很长的一段时间内,你会发现 5.x 还在广泛的被使用,目前最新的 5.x 版本是 5.6。对于当下,这并不是一个坏选项。然而,你应该尽快升级 - PHP 5.6 [将会在 2018 停止安全更新](http://php.net/supported-versions.php)。7.1 做了 [向下兼容][php71-bc] 处理,所以你的升级应该不会很难。. 如果你想查找一个函数及其用法,可以去官方手册 [php.net][php-docs] 中查找。
在很长的一段时间内,你会发现 5.x 还在广泛的被使用,目前最新的 5.x 版本是 5.6。对于当下,这并不是一个坏选项。然而,你应该尽快升级 - PHP 5.6 [已经在 2018 停止安全更新](http://php.net/supported-versions.php)。7.4 做了 [向下兼容][php74-bc] 处理,所以你的升级应该不会很难。. 如果你想查找一个函数及其用法,可以去官方手册 [php.net][php-docs] 中查找。

[php-release]: http://php.net/downloads.php
[php74-bc]: http://php.net/manual/migration74.incompatible.php
[php-docs]: http://php.net/manual/
[php71-bc]: http://php.net/manual/migration71.incompatible.php
42 changes: 23 additions & 19 deletions _posts/01-04-01-Mac-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,67 @@ title: Mac 安裝

## Mac 安装 {#mac_setup_title}

OS X 系统会预装 PHP, 只是一般情况下版本会比最新稳定版低一些。目前
Mavericks 是 5.4.17、Yosemite 则是 5.5.9,El Capitan 是 5.5.29、Sierra 是 5.6.24, 但在 PHP 7.1 出来之后, 这些往往是不够的。
macOS 系统会预装 PHP, 只是一般情况下版本会比最新稳定版低一些。

以下介绍几种在 OS X 上安装 PHP 的方法。
以下介绍几种在 macOS 上安装最新版本 PHP 的方法。

### 通过 Homebrew 安装 PHP

[Homebrew] 是一个强大的 OS X 专用包管理器, 它可以帮助你轻松的安装 PHP 和各种扩展。
[Homebrew] 是一个强大的 macOS 专用包管理器, 它可以帮助你轻松的安装 PHP 和各种扩展。
[Homebrew PHP] 是一个包含与 PHP 相关的 Formulae,能让你通过 homebrew 安装 PHP 的仓库。


也就是说, 你可以通过 `brew install` 命令安装 `php53`、`php54`、`php55`、`php56`、`php70`或者 `php71`,并且通过修改 `PATH` 变量来切换各个版本。或者你也可以使用 [brew-php-switcher][brew-php-switcher] 来自动切换。
也就是说, 你可以通过 `brew install` 命令安装 `php56`、`php70`、`php71`、`php72`、`php73` 或者 `php74`,使用以下命令安装最新版本:

brew install [email protected]

您可以通过修改 `PATH` 变量在 Homebrew PHP 版本之间切换。或者你也可以使用 [brew-php-switcher][brew-php-switcher] 来自动切换。

### Install PHP via Macports
### 通过 Macports 安装 PHP

[MacPorts] 是一个开源的,社区发起的项目,它的目的在于设计一个易于使用的系统,方便编译,安装以及升级 OS X 系统上的 command-line, X11 或者基于 Aqua 的开源软件。
[MacPorts] 是一个开源的,社区发起的项目,它的目的在于设计一个易于使用的系统,方便编译,安装以及升级 macOS 系统上的 command-line, X11 或者基于 Aqua 的开源软件。

MacPorts 支持预编译的二进制文件,因此你不必每次都重新从源码压缩包编译,如果你的系统没有安装这些包,它会节省你很多时间。


此时,你可以通过 `port install` 命名来安装 `php54`, `php55`, `php56`, `php70` 或者 `php71`,比如:
此时,你可以通过 `port install` 命名来安装 `php56`、`php70`、`php71`、`php72`、`php73` 或者 `php74`,比如:

sudo port install php56
sudo port install php71
sudo port install php74

你也可以执行 `select` 命令来切换当前的 php 版本:

sudo port select --set php php71
sudo port select --set php php74

### 通过 phpbrew 安装 PHP

[phpbrew] 是一个安装与管理多个 PHP 版本的工具。它在应用程序或者项目需要不同版本的 PHP 时非常有用,让你不再需要使用虚拟机来处理这些情况。

### 通过 Liip's binary installer 安装 PHP
[php-osx.liip.ch] 是另一种流行的选择,它提供了从 5.3 到 7.1 版本的单行安装功能。
[php-osx.liip.ch] 是另一种流行的选择,它提供了从 5.3 到 7.4 版本的单行安装功能。
它并不会覆盖Apple集成的PHP文件,而是将其安装在了一个独立的目录中(/usr/local/php5)。

### 源码编译

另一个让你控制安装 PHP 版本的选择就是 [自行编译][mac-compile]。
如果使用这种方法, 你必须先确认是否已经通过 Apple's Mac Developer Center」 下载、安装 [Xcode][xcode-gcc-substitution] 或者 ["Command Line Tools for XCode"]。
如果使用这种方法, 你必须先确认是否已经通过 AppleMac 开发人员中心下载、安装 [Xcode][xcode-gcc-substitution] 或者 ["XCode命令行工具(Command Line Tools for XCode)"][Command Line Tools for XCode]。

### 集成包 (All-in-One Installers)
### 集成环境 (All-in-One Installers)

上面列出的解决方案主要是针对 PHP 本身, 并不包含:比如 ApacheNginx 或者 SQL 服务器
集成包比如 [MAMP][mamp-downloads] 和 [XAMPP][xampp] 会安装这些软件并且将他们绑在一起,不过易于安装的背后也牺牲了一定的弹性。
上面列出的解决方案主要是针对 PHP 本身, 并不包含:比如 [Apache],[Nginx] 或者 SQL Server 之类的东西。
集成环境比如 [MAMP][mamp-downloads] 和 [XAMPP][xampp] 会安装这些软件并且将他们绑在一起,不过易于安装的背后也牺牲了一定的弹性。


[Homebrew]: http://brew.sh/
[Homebrew PHP]: https://github.com/Homebrew/homebrew-php#installation
[brew-php-switcher]: https://github.com/philcook/brew-php-switcher
[MacPorts]: https://www.macports.org/install.php
[phpbrew]: https://github.com/phpbrew/phpbrew
[php-osx.liip.ch]: http://php-osx.liip.ch/
[mac-compile]: http://php.net/install.macosx.compile
[php-osx.liip.ch]: https://php-osx.liip.ch/
[mac-compile]: https://secure.php.net/install.macosx.compile
[xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer
["Command Line Tools for XCode"]: https://developer.apple.com/downloads
[Command Line Tools for XCode]: https://developer.apple.com/downloads
[Apache]: https://httpd.apache.org/
[Nginx]: https://www.nginx.com/
[mamp-downloads]: http://www.mamp.info/en/downloads/
[xampp]: http://www.apachefriends.org/en/xampp.html
[brew-php-switcher]: https://github.com/philcook/brew-php-switcher
16 changes: 7 additions & 9 deletions _posts/01-05-01-Windows-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ title: Windows 安裝

你可以从 [windows.php.net/download][php-downloads] 下载二进制包。 解压后, 最好为你的 PHP 所在的根目录(php.exe 所在的文件夹)设置 [PATH][windows-path],这样就可以从命令行中直接执行 PHP。

如果只是学习或者本地开发,可以直接使用 PHP 5.4+ 内置的 Web 服务器, 还能省去配置服务器的麻烦。如果你想要包含有网页服务器以及 MySql 的集成包,那么像是[Web Platform Installer][wpi], [XAMPP][xampp], [EasyPHP][easyphp] 和 [WAMP][wamp] 这类工具将会帮助你快速建立 Windows 开发环境。不过这些工具将会与线上环境有些许差别,如果你是在 Windows 下开发,而生产环境则部署至 Linux ,请小心。
如果只是学习或者本地开发,可以直接使用 PHP 5.4+ 内置的 Web 服务器, 还能省去配置服务器的麻烦。如果你想要包含有网页服务器以及 MySql 的集成包,那么像是 [PhpStudy][phpstudy], [XAMPP][xampp] 和 [WAMP][wamp] 这类工具将会帮助你快速建立 Windows 开发环境。不过这些工具将会与线上环境有些许差别,如果你是在 Windows 下开发,而生产环境则部署至 Linux ,请小心。

如果你需要将生产环境部署在 Windows 上,那 IIS7 将会提供最稳定和最佳的性能。你可以使用 [phpmanager][phpmanager] (IIS7 的图形化插件) 让你简单的设置并管理 PHP。IIS7 也有内置的 FastCGI ,你只需要将 PHP 配置为它的处理器即可。更多详情请见[dedicated area on iis.net][php-iis]。

一般情况下,使用不同环境开发,会导致你在上线代码时出现 Bug。如果你在 Window 下开发将会用于 Linux 下运行的代码,请应该考虑使用 [虚拟机](/#virtualization_title).
一般情况下,使用不同环境开发,会导致你在上线代码时出现 Bug。如果你在 Window 下开发将会用于 Linux(或任何非Windows) 下运行的代码,请应该考虑使用 [虚拟机](/#virtualization_title).

这里推荐 Chris Tankersley 的一篇关于 Window 下工具使用的文章 - [Windows 下的 PHP 开发][windows-tools].

[easyphp]: http://www.easyphp.org/
[phpmanager]: http://phpmanager.codeplex.com/
[openserver]: http://open-server.ru/
[wamp]: http://www.wampserver.com/en/
[php-downloads]: http://windows.php.net/download/
[php-iis]: http://php.iis.net/
[windows-path]: http://www.windows-commandline.com/set-path-command-line/
[windows-tools]: http://ctankersley.com/2016/11/13/developing-on-windows-2016/
[wpi]: https://www.microsoft.com/web/downloads/platform.aspx
[phpstudy]: https://www.xp.cn/download.html
[xampp]: http://www.apachefriends.org/en/xampp.html
[wamp]: http://www.wampserver.com/en/
[phpmanager]: http://phpmanager.codeplex.com/
[php-iis]: http://php.iis.net/
[windows-tools]: http://ctankersley.com/2016/11/13/developing-on-windows-2016/
19 changes: 19 additions & 0 deletions _posts/01-06-01-Common-Directory-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
isChild: true
anchor: common_directory_structure
title: 常见目录结构
---

## 常见目录结构 {#common_directory_structure}

对于那些刚开始为web编写程序的人来说,一个常见的问题是:“我应该把我的文件放在哪里?” 多年来,这个答案一直是“DocumentRoot 指向的目录”。虽然这个答案还不完整,但这是一个很好的开始。

出于安全原因,配置文件不应该被人访问到; 因此,公共脚本保存在公共目录中,私有配置和数据保存在该目录之外。

对于 每个团队、CMS或框架,这些实体都有目录结构标准。但是,如果个人开发一个项目,那么选择使用哪种文件结构都是一件令人烦恼的事。

[Paul M. Jones] 对 github上成千上万的 PHP 项目中进行了研究。根据研究结果,他编写了一套标准文件和目录结构的标准,即 [Standard PHP Package Skeleton]。在这个目录结构中,`DocumentRoot` 应该指向 `public/`,单元测试应该在 `tests/`目录中,而 `composer` 安装的第三方包应该在 `vender/` 目录。对于其他文件和目录,遵循[标准的PHP包和框架目录标准][Standard PHP Package Skeleton]对项目的发展是非常有意义的。

[Paul M. Jones]: http://paul-m-jones.com/
[Standard PHP Package Skeleton]: https://github.com/php-pds/skeleton
[Composer]: /#composer_and_packagist
Loading