牛骨文教育服务平台(让学习变的简单)

前言

随着大量的框架使用composer和namespace,渐渐的线上环境也从之前的5.3变成了5.4或者5.5甚至5.6,随着7月份PHP7的发布,会有更多的公司采用新版本。

之前好久就想写这样的一片文章,来说明下各个版本的差异,这次算是拿出时间了。

这次的是第一篇,目前规划写三篇

  • PHP5.4.0
  • PHP5.5.0
  • PHP5.6.0

一方面是对自己的知识的整理,一方面是对自己的一次提升。

官方说明

官方文档地址 http://php.net/ChangeLog-5.php#5.4.0

详细说明

01 Mar 2012

原文

autoconf 2.59+ is now supported (and required) for generating the configure script with ./buildconf. Autoconf 2.60+ is desirable otherwise the configure help order may be incorrect.

翻译

autoconf 2.59 +现在支持(需要)生成配置脚本/ buildconf。autoconf 2.60 +是理想的配置,否则有可能是不正确的。

autoconf

php编译安装的时候需要的依赖软件,所以新版本对应配套的软件也要换成最新的对性能来讲才保险啊~

Removed legacy features 移除的特性

原文

  • break/continue $var syntax.
  • Safe mode and all related ini options.
  • register_globals and register_long_arrays ini options.
  • import_request_variables().
  • allow_call_time_pass_reference.
  • define_syslog_variables ini option and its associated function.
  • highlight.bg ini option.
  • Session bug compatibility mode (session.bug_compat_42 and session.bug_compat_warn ini options).
  • session_is_registered(), session_register() and session_unregister() functions.
  • y2k_compliance ini option.
  • magic_quotes_gpc, magic_quotes_runtime and magic_quotes_sybase ini options. get_magic_quotes_gpc, get_magic_quotes_runtime are kept but always return false, set_magic_quotes_runtime raises an E_CORE_ERROR.
  • Removed support for putenv(“TZ=..”) for setting the timezone.
  • Removed the timezone guessing algorithm in case the timezone isn’t set with date.timezone or date_default_timezone_set(). Instead of a guessed timezone, “UTC” is now used instead.

翻译

  • break/continue$ var语法。
  • 安全模式和所有相关的INI选项。
  • register_globals和register_long_arrays INI选项。
  • import_request_variables()。
  • allow_call_time_pass_reference。
  • define_syslog_variables INI选项及其相关的功能。
  • highlight.bg INI选项。
  • 会话错误兼容模式(session.bug_compat_42和session.bug_compat_warn INI选项)。
  • session_is_registered(),session_register()和session_unregister()功能。
  • y2k_compliance INI选项。
  • magic_quotes_gpc,magic_quotes_runtime和magic_quotes_sybase INI选项。get_magic_quotes_gpc,get_magic_quotes_runtime保存但始终返回false,set_magic_quotes_runtime引发e_core_error。
  • 不再支持putenv(“TZ = ..”)设置时区。
  • 如果不设置时区与时区date.timezone或date_default_timezone_set()除去猜测算法。而不是猜测的时区,“UTC”现在是用来代替。

我是拿百度翻译来的我会乱说吗? =_=

break/continue

移除了break/continue $var语法

在5.4之前,我们可以通过传递后面的参数来控制跳出或者停止若干层的循环,然而在5.4.0的版本之后,就去除了这个特性。

break $c;
continue $c;

break and continue accepts a number, that specify the number of nested loops, that should be breaked up, or continued.

参考资料

Safe mode and all related ini options. 去除安全模式以及在配置文件的选项

PHP 的安全模式是为了试图解决共享服务器(shared-server)安全问题而设立的。在结构上,试图在 PHP 层上解决这个问题是不合理的,但修改 web 服务器层和操作系统层显得非常不现实。因此许多人,特别是 ISP,目前使用安全模式。

语言的发展是在不断的进步的啊,也是一个不断试错改错的过程。^_^

  • 保安措施和安全模式,也就是移除了php.ini中所有safe_mode相关的配置项
  • 被安全模式限制或屏蔽的函数 。 在安全限制模式下,有些函数不能被使用。这个限制也将被移除

参考资料

register_globals and register_long_arrays ini options.

这两个配置项因为性能关系被移除了。

参考资料

import_request_variables()

>import_request_variables — 将 GET/POST/Cookie 变量导入到全局作用域中

>bool import_request_variables ( string types[,stringprefix ] )
将 GET/POST/Cookie 变量导入到全局作用域中。如果你禁止了 register_globals,但又想用到一些全局变量,那么此函数就很有用。

你可以使用 types 参数指定需要导入的变量。可以用字母‘G’、‘P’和‘C’分别表示 GET、POST 和 Cookie。这些字母不区分大小写,所以你可以使用‘g’、‘p’和‘c’的任何组合。POST 包含了通过 POST 方法上传的文件信息。注意这些字母的顺序,当使用“gp”时,POST 变量将使用相同的名字覆盖 GET 变量。任何 GPC 以外的字母都将被忽略。

prefix 参数作为变量名的前缀,置于所有被导入到全局作用域的变量之前。所以如果你有个名为“userid”的 GET 变量,同时提供了“pref_”作为前缀,那么你将获得一个名为 $pref_userid 的全局变量。

如果你对导入其它全局变量(例如 SERVER 变量)感兴趣,请考虑使用 extract()。

参考资料

allow_call_time_pass_reference

是否启用在函数调用时强制参数被按照引用传递。此方法已不被赞成并在 PHP/Zend 未来的版本中很可能不再支持。鼓励使用的方法是在函数定义中指定哪些参数应该用引用传递。鼓励大家尝试关闭此选项并确保脚本能够正常运行,以确保该脚本也能在未来的版本中运行(每次使用此特性都会收到一条警告,参数会被按值传递而不是按照引用传递)。

在函数调用时通过引用传递参数是不推荐的,因为它影响到了代码的整洁。如果函数的参数没有声明作为引用传递,函数可以通过未写入文档的方法修改其参数。要避免其副作用,最好仅在函数声明时指定那个参数需要通过引用传递。

参考资料

define_syslog_variables

初始化syslog相关的设置项,从这个版本进行了移除。

define_syslog_variables()只定义了全局变量。常数已经永远的定义,如果日志模块加载。你do not需要调用这个使用syslog常数。

也就是我们如果想要使用syslog相关的参数,直接调用就行,不需要进行手动初始化。

参考资料

highlight.bg ini option.

Colors for Syntax Highlighting mode. Anything that’s acceptable in would work.

和这个高亮相关配置项还有下面几个,对代码高亮的颜色进行配置

  • highlight.comment
  • highlight.default
  • highlight.html
  • highlight.keyword
  • highlight.string

参考资料

Session bug compatibility mode

php.ini中有说明
这是php4.3.0以后才有的安全设置。
出于安全的考虑php不建议你打开register_globals开关
但若关闭了register_globals(默认)时,session变量将不被自动转换成全局变量
此时传统的session变量注册方式session_register就失去意义了(session_register是把一个全局变量注册成session变量),因为访问session变量需要使用SESSION数组。因此只需直接操作_SESSION数组就可以了,而无须再用session_register注册了。以免产生混乱

开关session.bug_compat_42 和 session.bug_compat_warn 就是为了检查此类情况而设置的

参考资料

session_is_registered(), session_register() and session_unregister() functions.

这里提到的三个session相关的函数

  • session_is_registered()
  • session_register()
  • session_unregister()

这些是session相关的注册相关的函数。

参考资料

y2k_compliance ini option.

这。。。是关于2000的时候的千年虫的配置项。

参考资料

magic_quotes_gpc

magic_quotes_gpc,magic_quotes_runtime和magic_quotes_sybase INI选项。get_magic_quotes_gpc,get_magic_quotes_runtime保存但始终返回false,set_magic_quotes_runtime引发e_core_error。

这个配置被撤销之后,如果再使用就会引发错误。

Removed support for putenv(“TZ=..”) for setting the timezone

不再支持putenv(“TZ = ..”)设置时区,也就是不能再通过这个函数来设置时区相关的环境配置了.

添加 setting 到服务器环境变量。 环境变量仅存活于当前请求期间。 在请求结束时环境会恢复到初始状态。

设置特定的环境变量也有可能是一个潜在的安全漏洞。 safe_mode_allowed_envvars 包含了一个以逗号分隔的前缀列表。 在安全模式下,用户可以仅能修改用该指令设定的前缀名称的指令。 默认情况下,用户仅能够修改以 PHP 开头的环境变量(例如 PHP_FOO=BAR)。 注意:如果此指令是空的,PHP允许用户设定任意环境变量!

可见这个函数真是危险啊。。。

参考资料

Removed the timezone guessing algorithm in case the timezone isn’t set with date.timezone or date_default_timezone_set(). Instead of a guessed timezone, “UTC” is now used instead.



如果不设置时区与时区date.timezone或date_default_timezone_set()除去猜测算法。而不是猜测的时区,“UTC”现在是用来代替。

> date_default_timezone_set() 设定用于所有日期时间函数的默认时区。

> Note:   
 自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。

参考资料

- [http://php.net/manual/zh/function.date-default-timezone-set.php](http://php.net/manual/zh/function.date-default-timezone-set.php)

### Moved extensions to PECL 移动扩展PECL

原文

- ext/sqlite. (Note: the ext/sqlite3 and ext/pdo_sqlite extensions are not affected)

翻译

- EXT / SQLite。(注:EXT / sqlite3和EXT / pdo_sqlite扩展不受影响)

### ext/sqlite
> This package is not maintained anymore and has been superseded. Package has moved to channel [http://php.net/sqlite](http://php.net/sqlite), package .   
 这个包是不是保持了与已被取代。包已经转移到渠道[http://php.net/sqlite](http://php.net/sqlite),包。

也就是说这个sqlite从pecl转移到了SQLite的扩展中。

参考资料

- [http://pecl.php.net/package/SQLite](http://pecl.php.net/package/SQLite)
- [http://php.net/sqlite](http://php.net/sqlite)

### General improvements 一般的改进

原文

- Added short array syntax support ([1,2,3]), see UPGRADING guide for full details.
- Added binary numbers format (0b001010).
- Added support for Class::{expr}() syntax.
- Added multibyte support by default. Previously php had to be compiled with –enable-zend– multibyte. Now it can be enabled or disabled through zend.multibyte directive in php.ini.
- Removed compile time dependency from ext/mbstring.
- Added support for Traits.
- Added closure $this support back.
- Added array dereferencing support.
- Added callable typehint.
- Added indirect method call through array. #47160.
- Added DTrace support.
- Added class member access on instantiation (e.g. (new foo)->bar()) support.
- `<?=`is now always available regardless of the short_open_tag setting.
- Implemented Zend Signal Handling (configurable option –enable-zend-signals, off by default).
- Improved output layer, see README.NEW-OUTPUT-API for internals.
- lmproved unix build system to allow building multiple PHP binary SAPIs and one SAPI module the same time. #53271, #52419.
- Implemented closure rebinding as parameter to bindTo.
- Improved the warning message of incompatible arguments.
- Improved ternary operator performance when returning arrays.
- Changed error handlers to only generate docref links when the docref_root INI setting is not empty.
- Changed silent conversion of array to string to produce a notice.
- Changed default value of “default_charset” php.ini option from ISO-8859-1 to UTF-8.
- Changed silent casting of null/”/false into an Object when adding a property into a warning.
- Changed E_ALL to include E_STRICT.
- Disabled windows CRT warning by default, can be enabled again using the ini directive windows_show_crt_warnings.
- Fixed bug #55378: Binary number literal returns float number though its value is small enough.

翻译

- 添加短数组语法支持([1,2,3]),详情见升级指南。
- 添加二进制格式(0b001010)。
- 增加支持类::{ }()表达式的语法。
- 添加多字节默认支持。以前的PHP必须编译——使Zend字节。现在可以启用或禁用通过zend.multibyte指令在php.ini。
- 从EXT / mbstring编译时依赖。
- 增加支持的特征。
- 添加关闭美元的支持。
- 添加数组引用的支持。
- 添加可赎回typehint。
- 增加间接方法调用通过阵列。# 47160。
- 加入DTrace支持。
- 添加类成员访问实例(例如(新富)-> bar())支持。
- `<?=`永远是现在可用的short_open_tag设置。
- 实现Zend信号处理(可配置的选项——启用Zend信号,默认关闭)。
- 改进的输出层,看到readme.new-output-api内部。
- 改进的UNIX系统允许建立建设多个PHP二进制SAPIs和SAPI模块相同的时间。# 53271,# 52419。
- 实施关闭绑定参数的结合。
- 改进的相互矛盾的警告信息。
- 三元运算符返回时阵列性能改进。
- 改变错误处理程序只产生docref链接时,docref_root ini设置不空。
- 改变数组字符串生成通知无声的转换。
- 改变默认值“default_charset”的选项从ISO-8859-1为UTF-8。
- 改变沉默铸造空/”/假为对象添加属性到一个警告。
- 改变e_all包括e_strict。
- 禁用Windows CRT警告默认情况下,可以再次启用使用INI指令windows_show_crt_warnings。
- 固定的错误# 55378:二进制数的文本返回浮点数的值足够小,虽然。

*发现这么翻译还不如不翻译看的明白。。。。*

### short array syntax support 短数组支持

<?php
$array = array(

"foo" => "bar",
"bar" => "foo",

);

// 自 PHP 5.4 起
$array = [

"foo" => "bar",
"bar" => "foo",

];
?>


参考资料

- [http://cn.php.net/manual/zh/language.types.array.php](http://cn.php.net/manual/zh/language.types.array.php)

### binary numbers format 二进制直接量

从PHP5.4开始, 我们可以直接在代码中书写二进制直接量了. 这个在定义一些标志位的时候, 尤为方便.

$bin = 0b1101;
echo $bin;

//13


参考资料

- [http://www.laruence.com/2011/10/10/2232.html](http://www.laruence.com/2011/10/10/2232.html)

### support for Class::{expr}() syntax

Makes PHP more flexible, when calling class/object methods.

$method = "method";

$test = new Test();

$test->method();
$test->$method();
$test->{"method"}();

Test::method();
Test::$method();
Test::{"method"}();


参考资料

- [http://yogurt.iteye.com/blog/1447483](http://yogurt.iteye.com/blog/1447483)

### multibyte support 多字节支持

添加多字节默认支持。以前的PHP必须编译——使Zend字节。现在可以启用或禁用通过zend.multibyte指令在php.ini。

参考资料

- [http://www.laruence.com/2011/11/18/2305.html](http://www.laruence.com/2011/11/18/2305.html)
- [http://serverfault.com/questions/145413/php-what-is-enable-zend-multibyte-configure-option-for](http://serverfault.com/questions/145413/php-what-is-enable-zend-multibyte-configure-option-for)

### Removed compile time dependency from ext/mbstring

从EXT / mbstring编译时依赖

### Added support for *Traits *
> 自 PHP 5.4.0 起,PHP 实现了代码复用的一个方法,称为 traits。

> Traits 是一种为类似 PHP 的单继承语言而准备的代码复用机制。Trait 为了减少单继承语言的限制,使开发人员能够自由地在不同层次结构内独立的类中复用方法集。Traits 和类组合的语义是定义了一种方式来减少复杂性,避免传统多继承和混入类(Mixin)相关的典型问题。

> Trait 和一个类相似,但仅仅旨在用细粒度和一致的方式来组合功能。Trait 不能通过它自身来实例化。它为传统继承增加了水平特性的组合;也就是说,应用类的成员不需要继承

参考资料

- [http://php.net/manual/zh/language.oop5.traits.php](http://php.net/manual/zh/language.oop5.traits.php)

### Added closure $this support back
> 用于代表 匿名函数 的类.

> 匿名函数(在 PHP 5.3 中被引入)会产生这个类型的对象。在过去,这个类被认为是一个实现细节,但现在可以依赖它做一些事情。自 PHP 5.4 起,这个类带有一些方法,允许在匿名函数创建后对其进行更多的控制。

> 除了此处列出的方法,还有一个 __invoke 方法。这是为了与其他实现了 __invoke()魔术方法 的对象保持一致性,但调用匿名函数的过程与它无关。

待续。。

参考资料

- [http://php.net/manual/zh/class.closure.php](http://php.net/manual/zh/class.closure.php)
- [http://stackoverflow.com/questions/5734011/php-5-4-closure-this-support](http://stackoverflow.com/questions/5734011/php-5-4-closure-this-support)
- [https://eval.in/private/f2fb0986b99669](https://eval.in/private/f2fb0986b99669)
- [https://wiki.php.net/rfc/closures](https://wiki.php.net/rfc/closures)

### Added array dereferencing support

可以说上是直接获取数组中的元素吧,对于我们来说还是很方便的,能省下一个变量。

> 在以前, 我们如果定义一个返回数组的函数:

<?php
function foo() {

return array(1, 2, 3);

}

> 那么, 如果我要获取返回数组中的第二个元素, 就只能:

<?php
list(, $mid, ) = foo();
//或者:
$tmp = $foo();
$mid = $tmp[1];

> 而从5.4开始, 我们就不需要这么麻烦了, 只需要:

<?php
$mid = foo()[1];

> 另外, 也可以使用引用:

<?php
function &getTable() {

 return $GLOBALS;

}

getTable()["foo"] = "laruence";

echo $foo;

//laruence


参考资料

- [http://www.laruence.com/2011/10/10/2212.html](http://www.laruence.com/2011/10/10/2212.html)

### 函数类型提示(Callable typehint)

要想了解这个首先需要了解的是类型约束

> PHP 5 可以使用类型约束。函数的参数可以指定必须为对象(在函数原型里面指定类的名字),接口,数组(PHP 5.1 起)或者 callable(PHP 5.4 起)。不过如果使用 NULL 作为参数的默认值,那么在调用函数的时候依然可以使用 NULL 作为实参。

> 如果一个类或接口指定了类型约束,则其所有的子类或实现也都如此。

> 类型约束不能用于标量类型如 int 或 string。Traits 也不允许

/**
 * 测试函数
 * 第一个参数必须为 OtherClass 类的一个对象
 */
public function test(OtherClass $otherclass) {
    echo $otherclass->var;
}

其中的OtherClass 就是我们的类型约束

在PHP5.4版本中,新增了Callable类型的类型约束

<?php
function foo(callable $callback) {
}


<?php
foo("false"); //Catchable fatal error: Argument 1 passed to foo() must be callable *
foo("printf"); //okey
foo(function(){}); //okey

class A {

static function show() {
}

}

foo(array("A", "show")); //okey


参考资料

- [http://www.laruence.com/2011/10/10/2229.html](http://www.laruence.com/2011/10/10/2229.html)
- [http://www.laruence.com/2011/07/02/2102.html](http://www.laruence.com/2011/07/02/2102.html)
- [http://php.net/manual/zh/language.oop5.typehinting.php](http://php.net/manual/zh/language.oop5.typehinting.php)

### indirect method call through array 通过间接方法调用的数组

这里在后面还有一个#47160的bug.

<?php
// For 5.2.x as well.
class Thing {

static function DoesStuff() {
    echo "Hello, World";
}

}

$f = array("Thing", "DoesStuff");

$f();

//返回 Hello, World
?>


按照bug页面上的,之前的版本就会返回错误,现在已经好啦~

<?php

class Hello {

//这是一个静态的方法

static public function world($x) {

 echo "Hello, $x
";

}
}

function hello_world($x) {
echo "Hello, $x ";
}

//数组中包含了三个,第一个数组,第二个匿名函数,第三个字符串
$callbacks = array(
array("Hello", "world"),
function ($x) { echo "Hello, $x "; },
"hello_world"
);

//循环了数组
foreach ($callbacks as $k => $callback) {
if (is_callable($callback)) { //检测参数是否为合法的可调用结构

 $callback($k);  //然后就把自己的key值作为参数传递过去了 

}
}

//RESULT:
//Hello, 0 指向了Hello的world静态方法
//Hello, 1 参数本身就是匿名函数,是可以直接执行的
//Hello, 2 作为字符串的参数可以找到相同名字的方法,所以执行了

//CalvinLee
?>


上面的第一个栗子说明了我们可以通过数组的形式直接调用方法,确认回调函数,通过`array("类","方法")`的方式进行直接调用。

这是一个因为bug造成的新特性。

参考资料

- [https://bugs.php.net/bug.php?id=47160](https://bugs.php.net/bug.php?id=47160)
- [https://wiki.php.net/rfc/indirect-method-call-by-array-var](https://wiki.php.net/rfc/indirect-method-call-by-array-var)
- [http://php.net/manual/zh/function.is-callable.php](http://php.net/manual/zh/function.is-callable.php)

### DTrace 支持
> DTrace(全称Dynamic Tracing),也称为动态跟踪,是由 Sun™ 开发的一个用来在生产和试验性生产系统上找出系统瓶颈的工具,可以对内核(kernel)和用户应用程序(user application)进行动态跟踪并且对系统运行不构成任何危险的技术。在任何情况下它都不是一个调试工具, 而是一个实时系统分析寻找出性能及其他问题的工具。

也就是这个调试工具可以直接支持PHP辣!可以进行更深层次的代码调试。

有时间可以研究一下这个怎么用。

。。。

参考资料

- [https://blogs.oracle.com/shanti/entry/dtrace_support_for_php](https://blogs.oracle.com/shanti/entry/dtrace_support_for_php)
- [http://php.net/manual/zh/features.dtrace.dtrace.php](http://php.net/manual/zh/features.dtrace.dtrace.php)
- [http://baike.baidu.com/view/3223769.htm](http://baike.baidu.com/view/3223769.htm)
- [http://blog.experimentalworks.net/2010/04/php-5-3-99-dev-and-dtrace-part-i/](http://blog.experimentalworks.net/2010/04/php-5-3-99-dev-and-dtrace-part-i/)

### 在实例化类成员的访问支持

class Test {

public function foo() {
    return $this;
}

public function bar() {
    return "oh hai";
}

}

$t = (new Test)->foo();

print $t->bar();


我们可以直接调用啦啦啦~

很方便的样子!

参考资料

- [http://stackoverflow.com/questions/9551251/php-class-member-access-on-instantiation](http://stackoverflow.com/questions/9551251/php-class-member-access-on-instantiation)

### <?= 短标签

PHP5.4里默认开启了短标签设置,支持了行内的短标签 `<?=   ?>`

<?php
$a = 2;
?>
<?=$a?>


这个短标签直接输出了,所以是用于行内的。

参考资料

- [http://php.net/manual/zh/language.basic-syntax.phptags.php](http://php.net/manual/zh/language.basic-syntax.phptags.php)

### Zend Signal Handling

实现Zend Signal Handling(可配置的选项——–enable-zend-signals,默认关闭)

> 新的机制, 叫做zend signal, 它的理念, 来自Yahoo的”延迟信号处理”(Yahoo signal deferring mechanism), 而后, facebook把这套理念加入了PHP中, 为了提升PHP+Apache 1.X下PHP调用ap_block/ap_unblock的性能

参考资料

- [http://www.laruence.com/2011/10/19/2247.html](http://www.laruence.com/2011/10/19/2247.html)
- [http://www.laruence.com/2008/12/31/647.html](http://www.laruence.com/2008/12/31/647.html)
- [http://www.laruence.com/2011/01/27/1854.html](http://www.laruence.com/2011/01/27/1854.html)
- [https://wiki.php.net/rfc/zendsignals](https://wiki.php.net/rfc/zendsignals)

### Improved output layer, see README.NEW-OUTPUT-API for internals

改进的输出层,看到readme.new-output-api内部

看起来像是内核的输出层改动,但是实在是找不到资料,不知道怎么理解这一条。QAQ

### multiple PHP binary SAPIs and one SAPI module 多个PHP二进制SAPIs和SAPI模块

改进的UNIX系统允许建立建设多个PHP二进制SAPIs和SAPI模块相同的时间。#53271, #52419.

这里在后面提到了两个bug。

> Using configure options –enable-cgi and –enable-fpm together will not produce the php-cgi binary.

两个配置一起的时候就不会产生php-cgi的二进制。   
两个模块作为配置项的时候会编译失败。

参考资料

- [https://bugs.php.net/bug.php?id=53271](https://bugs.php.net/bug.php?id=53271)
- [https://bugs.php.net/bug.php?id=52419](https://bugs.php.net/bug.php?id=52419)
- [http://php.net/manual/en/install.pecl.php-config.php](http://php.net/manual/en/install.pecl.php-config.php)
- [http://blog.sina.com.cn/s/blog_7cc2d3440100v6mf.html](http://blog.sina.com.cn/s/blog_7cc2d3440100v6mf.html)
- [http://php.find-info.ru/php/016/ch23lev1sec1.html](http://php.find-info.ru/php/016/ch23lev1sec1.html)
- [http://www.cnblogs.com/zl0372/articles/php_17.html](http://www.cnblogs.com/zl0372/articles/php_17.html)
- [http://www.laruence.com/2008/08/12/180.html](http://www.laruence.com/2008/08/12/180.html)

### Implemented closure rebinding as parameter to bindTo 实施关闭重新绑定的参数结合
> Closure::bind — 复制一个闭包,绑定指定的$this对象和类作用域。   
 Closures: Object extension 关闭对象扩展

这里需要理解一个Closure的概念,Closure 类,匿名函数类。

> 匿名函数(在 PHP 5.3 中被引入)会产生这个类型的对象。在过去,这个类被认为是一个实现细节,但现在可以依赖它做一些事情。自 PHP 5.4 起,这个类带有一些方法,允许在匿名函数创建后对其进行更多的控制

<?php

class APP {

public $var = 25;

public function __construct() {

}

public function get($callback) {
    if (!is_callable($callback)) {
        throw new InvalidArgumentException("Paran must be callable.");
    }
    // $callback->bindTo($this);

// $callback->bindTo($this, $this);
// $callback();

    //上面的回调方法找不到绑定的对象,下面的方法是用一个新的变量来做绑定函数的结果,然后执行
    $callback1 = $callback->bindTo($this, $this);
    $callback1();
}

}

$app = new APP();
$app->get(function() use ($app) {//作为自己的匿名函数

echo "<pre>";
var_dump($app);
echo "<br />";
var_dump($this);

});
?>


参考资料

- [http://blog.csdn.net/iefreer/article/details/8927045](http://blog.csdn.net/iefreer/article/details/8927045)
- [http://php.net/manual/zh/closure.bindto.php](http://php.net/manual/zh/closure.bindto.php)
- [http://php.net/manual/zh/closure.bind.php](http://php.net/manual/zh/closure.bind.php)
- [https://wiki.php.net/rfc/closures](https://wiki.php.net/rfc/closures)

### Improved the warning message of incompatible arguments 改进的不兼容的参数的警告信息

就是字面上的意思。。。

### Improved ternary operator performance when returning arrays 三元运算符返回时数组性能改进

优化了数组的时候的性能,当返回值是array的时候速度得到了提升。

参考资料
- [http://www.laruence.com/2011/11/04/2258.html](http://www.laruence.com/2011/11/04/2258.html)  
- [http://grokbase.com/t/php/php-internals/11aeyhp2ek/ternary-operator-performance-improvements](http://grokbase.com/t/php/php-internals/11aeyhp2ek/ternary-operator-performance-improvements)  
- [http://php.net/manual/en/language.operators.comparison.php](http://php.net/manual/en/language.operators.comparison.php)

### Changed error handlers 改变错误处理程序只产生docref链接时,docref_root ini设置不空

当配置文件 php.ini 中的 docref_root 的值为空的时候,更改了 docref links 指向的链接。

也就是对默认的指向的错误提醒的页面连接进行了修改.

修改默认值不属于很重要的功能,对于这种更新对项目来说不是特别的重要。

> 新的错误信息格式包含了对应的参考页面,该页面对错误进行具体描述,或者描述了导致该错误发生的函数。为了提供手册的页面,你可以在PHP官方站点下载对应语言的手册,并在ini中设置网址到本地对应的地址。如果你的本地手册拷贝可以使用”/manual/” 访问,你就可以简单的设置 docref_root=/manual/。另外你还需要设置 docref_ext 匹配你本地文件的后缀名 docref_ext=.html。当然也可以设置一个外部的参考地址。例如你可以设置 docref_root=[http://manual/en/](http://manual/en/) 或者 docref_root=”http://landonize.it/?how=url&theme=classic&filter=Landon &url=http%3A%2F%2Fwww.php.net%2F”

> 通常需要在 docref_root 后面以 “/”结尾, 但是在以上的第二种示例情况中不必这么设置。

> Note:

> 因为这么做可以快速定位和查看到函数的说明,所以它对你的开发会非常有用。建议永远不要再生产系统中使用 (例如系统被连接到互联网对外提供服务)。 

参考资料

- [http://php.net/manual/zh/errorfunc.configuration.php#ini.docref-root](http://php.net/manual/zh/errorfunc.configuration.php#ini.docref-root)
- [http://php.net/manual/en/function.main.php](http://php.net/manual/en/function.main.php)
- [https://perishablepress.com/advanced-php-error-handling-via-htaccess/](https://perishablepress.com/advanced-php-error-handling-via-htaccess/)

### Changed silent conversion of array to string to produce a notice 改变了数组转换字符串的提醒

木有看明白。。。。

参考资料

- [http://stackoverflow.com/questions/3389582/notice-array-to-string-conversion-why](http://stackoverflow.com/questions/3389582/notice-array-to-string-conversion-why)
- [http://stackoverflow.com/questions/20117856/php-array-to-string-as-parameters](http://stackoverflow.com/questions/20117856/php-array-to-string-as-parameters)
- [http://stackoverflow.com/questions/7244564/notice-array-to-string-conversion](http://stackoverflow.com/questions/7244564/notice-array-to-string-conversion)
- [http://grokbase.com/t/php/php-bugs/11b2a951bt/php-bug-bug-60198-new-array-to-string-notice-from-array-functions](http://grokbase.com/t/php/php-bugs/11b2a951bt/php-bug-bug-60198-new-array-to-string-notice-from-array-functions)

### Changed default value of “default_charset” php.ini option from ISO-8859-1 to UTF-8 改变默认值“default_charset”的选项从ISO-8859-1为UTF-8

默认设置是UTF-8.

> PHP always outputs a character encoding by default in the Content-type: header. To disable sending of the charset, simply set it to be empty. 

有趣的是这次发现了国内的工程师的提交的bug~

参考资料

- [https://bugs.php.net/bug.php?id=61354](https://bugs.php.net/bug.php?id=61354)
- [http://grokbase.com/t/php/php-internals/123cfv42tq/default-charset-confusion](http://grokbase.com/t/php/php-internals/123cfv42tq/default-charset-confusion)
- [http://news.php.net/php.internals/58853](http://news.php.net/php.internals/58853)

### Changed silent casting of null/”/false into an Object when adding a property into a warning 当一个对象中有空的属性时加入了一个警告

当给一个对象加入一个属性的时候,扔掉null或者false会返回一个警告

### Changed E_ALL to include E_STRICT E_ALL中包括了E_STRICT

参考资料

- [http://www.zhuwenbo.net/?p=146](http://www.zhuwenbo.net/?p=146)

### Disabled windows CRT warning by default, can be enabled again using the ini directive windows_show_crt_warnings 禁用Windows CRT警告默认情况下,可以再次启用使用INI指令windows_show_crt_warnings

windows CRT 

> Visual Studio 2012 更新 1 支持的 Windows 8,Windows Server 2012,Windows 7,Windows Server 2008中,Windows Vista,Windows XP Service Pack 3 (SP3) C 运行库,x86 的 Windows XP Service Pack 2 (SP2) x64 和 Windows Server 2003 Service Pack 2 (SP2) x86 和 x64 的。 所有这些操作系统支持 Windows 应用程序编程接口 (API) (API) 提供和 Unicode 支持。 此外,所有 Win32 应用程序中使用多字节字符集 (MBCS)。

This directive shows the Windows CRT warnings when enabled. These warnings were displayed by default until PHP 5.4.0. 

> This directive shows the Windows CRT warnings when enabled. These warnings were displayed by default until PHP 5.4.0. 

参考资料

- [http://blog.csdn.net/wwl33695/article/details/8472291](http://blog.csdn.net/wwl33695/article/details/8472291)
- [http://cn.php.net/manual/zh/ini.core.php#ini.windows-show-crt-warning](http://cn.php.net/manual/zh/ini.core.php#ini.windows-show-crt-warning)

### Fixed bug #55378: Binary number literal returns float number though its value is small enough 固定的错误# 55378:二进制数的文本返回浮点数虽然其值足够小

上面提到过这个版本支持了直接的二进制的输出,所以这条就是修复返回二进制转换的浮点数的错误。

Test script:

<?php
var_dump(0b1111111);
var_dump(0b1111111111111111);

Expected result:

int(127)
int(65535)

Actual result:

int(127)
float(65535)


参考资料

- [https://bugs.php.net/bug.php?id=55378](https://bugs.php.net/bug.php?id=55378)

### Improved Zend Engine memory usage 改进的内存使用Zend引擎

原文

- Improved parse error messages.
- Replaced `zend_function.pass_rest_by_reference` by `ZEND_ACC_PASS_REST_BY_REFERENCE` in zend_function.fn_flags.
- Replaced `zend_function.return_reference` by `ZEND_ACC_RETURN_REFERENCE` in zend_function.fn_flags.
- Removed `zend_arg_info.required_num_args` as it was only needed for internal functions. Now the first arg_info for internal functions (which has special meaning) is represented by `zend_internal_function_info` structure.
- Moved `zend_op_array.size`, `size_var`, `size_literal`, `current_brk_cont`, backpatch_count into CG(`context`) as they are used only during compilation.
- Moved `zend_op_array.start_op` into EG(`start_op`) as it’s used only for ‘interactive’ execution of single top-level op-array.
- Replaced `zend_op_array.done_pass_two` by `ZEND_ACC_DONE_PASS_TWO` in `zend_op_array.fn_flags`.   
op_array.vars array is trimmed (reallocated) during pass_two.
- Replaced `zend_class_entry.constants_updated` by `ZEND_ACC_CONSTANTS_UPDATED` in `zend_class_entry.ce_flags`.
- Reduced the size of `zend_class_entry` by sharing the same memory space by different information for internal and user classes. See `zend_class_entry.info` union.
- Reduced size of temp_variable.

翻译

- 
改进的解析错误消息。

- 
通过更换zend_function.pass_rest_by_reference zend_acc_pass_rest_by_reference在zend_function.fn_flags。

- 
通过更换zend_function.return_reference zend_acc_return_reference在zend_function.fn_flags。

- 
删除zend_arg_info.required_num_args因为这只是内部功能的需要。现在内部功能的第一arg_info(具有特殊意义的zend_internal_function_info结构表示)。

- 
移动zend_op_array.size,size_var,size_literal,current_brk_cont,backpatch_count为CG(上下文)作为他们在编译过程中只使用。

- 
移动zend_op_array.start_op成如(start_op)它只用于“单顶级运算阵列交互执行。

- 
通过更换zend_op_array.done_pass_two zend_acc_done_pass_two在zend_op_array.fn_flags。

- 
op_array.vars阵列在pass_two修剪(重新分配)。

- 
通过更换zend_class_entry.constants_updated zend_acc_constants_updated在zend_class_entry.ce_flags。

- 
减少zend_class_entry大小由内部和用户类不同信息共享相同的内存空间。看到zend_class_entry.info联盟。

- 
temp_variable缩小。

这部分的说明是关于zend引擎相关的,按目前我的水平还不是能很明白的理解这些的含义。

### Improved Zend Engine, performance tweaks and optimizations 改进的Zend引擎,性能调整和优化

原文

- Inlined most probable code-paths for arithmetic operations directly into executor.
- Eliminated unnecessary iterations during request startup/shutdown.
- Changed `$GLOBALS` into a JIT autoglobal, so it’s initialized only if used. (this may affect opcode caches!)
- Improved performance of @ (silence) operator.
- Simplified string offset reading. `$str[1][0]` is now a legal construct.
- Added caches to eliminate repeatable run-time bindings of functions, classes, constants, methods and properties.
- Added concept of interned strings. All strings constants known at compile time are allocated in a single copy and never changed.
- `ZEND_RECV` now always has `IS_CV` as its result.
- `ZEND_CATCH` has to be used only with constant class names.
- `ZEND_FETCH_DIM_?` may fetch array and dimension operands in different order.
- Simplified `ZEND_FETCH_*_R`operations. They can’t be used with the `EXT_TYPE_UNUSED`flag any more. This is a very rare and useless case. `ZEND_FREE` might be required after them instead.
- Split `ZEND_RETURN` into two new instructions `ZEND_RETURN` and `ZEND_RETURN_BY_REF`.
- Optimized access to global constants using values with pre-calculated hash_values from the literals table.
- Optimized access to static properties using executor specialization. A constant class name may be used as a direct operand of `ZEND_FETCH_*` instruction without previous `ZEND_FETCH_CLASS`.
- zend_stack and zend_ptr_stack allocation is delayed until actual usage.

翻译

- 
内联最可能的代码路径,直接进入执行算术运算。

- 
消除不必要的迭代请求启动/关机时。

- 
改变成一个JIT autoglobal =美元,所以它的初始化,如果使用。(这可能会影响操作码缓存!)

- 
改进的性能”(沉默)算子。

- 
简化的字符串偏移阅读。$str [ 1 ] [ 0 ]现在的法律构建。

- 
消除重复的运行时绑定的功能,添加缓存类,常量,方法和属性。

- 
拘留字符串添加的概念。所有字符串常量在编译时被分配在一个单拷贝,永远都不会改变的。

- 
zend_recv现在总是is_cv作为结果。

- 
zend_catch现在只需要进行不断的类名称。

- 
zend_fetch_dim_?可以把不同排列和尺寸数。

- 
简化zend_fetch_ * _r操作。他们不能用任何ext_type_unused旗。这是一个非常难得的和无用的情况下。- zend_free可能在他们的要求。

- 
zend_return分裂为两个新的指令zend_return和zend_return_by_ref。

- 
优化访问全局常量使用的值与预先计算的hash_values从文字表。

- 
优化访问静态属性用遗嘱执行人专业化。一个恒定的类的名称可以作为直接操作数指令没有以前的zend_fetch_class zend_fetch_ *。

- 
zend_stack和zend_ptr_stack分配延迟到实际使用。

- 
改进的Zend引擎,性能调整和优化

机翻好渣。。。。。等我长发及腰,再来看这个可好QAQ

### Other improvements to Zend Engine 在Zend引擎改进

原文

- Added an optimization which saves memory and emalloc/efree calls for empty HashTables.
- Added ability to reset user opcode handlers.
- Changed the structure of op_array.opcodes. The constant values are moved from opcode operands into a separate literal table.
- Fixed (disabled) inline-caching for ZEND_OVERLOADED_FUNCTION methods.
- 
Fixed bug #43200 (Interface implementation / inheritence not possible in abstract classes).

翻译

- 
增加了一个优化,节省内存和emalloc /饱和需要空表。

- 
新增能力重置用户操作处理程序。

- 
改变了op_array.opcodes结构。该常数的值是从操作码操作数为一个单独的文字表。

- 
固定(禁用)为zend_overloaded_function方法内联缓存。

- 
固定的错误# 43200(接口的实现/继承抽象类不可能)。

![PHP结构](https://box.kancloud.cn/2016-03-17_56ea1b293701b.jpg "")

zend引擎作为底层,还是需要我理解更深入再去看啦~

### 后记

### 关于PHP

PHP作为流行的脚本语言,上手非常快,但是这并不代表这个一个糟糕的语言,从这个版本的更新记录,我也看到了每次的改进,以及社区内大家的努力。

这次做ChangeLog的整理大概会写三个文章共六篇,由于这个Log实在是太长了还是写一半先发出去比较好~

引用的资料在每个小结后面都有,方便自己和大家查阅。

如果发现描述错误,请务必评论或者私信我,如果有错,发现了就不能再错下去~

### 关于整理资料

我们依靠网络,每天在接触着很多的新闻和资料,对我们来讲,从这些里面找出有用的知识并吸收还是有一定难度的,特别是国内糟糕的博客环境,一个文章发布出来之后会有好多网站抄袭抓取,内容还不全,对于初学者会造成负面影响,且珍惜。

### 关于个人成长

当有一个大目标的时候,才可以转化成小目标进行执行。   
执行力永远放在第一位。