### 前言
隨著大量的框架使用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](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.
參考資料
- [http://stackoverflow.com/questions/6517401/what-is-the-break-continue-var-syntax-will-be-removed-in-php-5-4](http://stackoverflow.com/questions/6517401/what-is-the-break-continue-var-syntax-will-be-removed-in-php-5-4)
- [http://php.net/control-structures.break](http://php.net/control-structures.break)
### Safe mode and all related ini options. 去除安全模式以及在配置文件的選項
PHP 的安全模式是為了試圖解決共享服務器(shared-server)安全問題而設立的。在結構上,試圖在 PHP 層上解決這個問題是不合理的,但修改 web 服務器層和操作系統層顯得非常不現實。因此許多人,特別是 ISP,目前使用安全模式。
語言的發展是在不斷的進步的啊,也是一個不斷試錯改錯的過程。^_^
- 保安措施和安全模式,也就是移除了php.ini中所有safe_mode相關的配置項
- 被安全模式限制或屏蔽的函數 。 在安全限制模式下,有些函數不能被使用。這個限制也將被移除
參考資料
- [http://php.net/manual/zh/features.safe-mode.php](http://php.net/manual/zh/features.safe-mode.php)
### register_globals and register_long_arrays ini options.
這兩個配置項因為性能關系被移除了。
參考資料
- [http://php.net/manual/zh/ini.core.php#ini.register-globals](http://php.net/manual/zh/ini.core.php#ini.register-globals)
### 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()。
參考資料
- [http://php.net/manual/zh/function.import-request-variables.php](http://php.net/manual/zh/function.import-request-variables.php)
### allow_call_time_pass_reference
> 是否啟用在函數調用時強制參數被按照引用傳遞。此方法已不被贊成并在 PHP/Zend 未來的版本中很可能不再支持。鼓勵使用的方法是在函數定義中指定哪些參數應該用引用傳遞。鼓勵大家嘗試關閉此選項并確保腳本能夠正常運行,以確保該腳本也能在未來的版本中運行(每次使用此特性都會收到一條警告,參數會被按值傳遞而不是按照引用傳遞)。
> 在函數調用時通過引用傳遞參數是不推薦的,因為它影響到了代碼的整潔。如果函數的參數沒有聲明作為引用傳遞,函數可以通過未寫入文檔的方法修改其參數。要避免其副作用,最好僅在函數聲明時指定那個參數需要通過引用傳遞。
參考資料
- [http://php.net/manual/zh/ini.core.php#ini.allow-call-time-pass-reference](http://php.net/manual/zh/ini.core.php#ini.allow-call-time-pass-reference)
- [http://blog.csdn.net/shimch/article/details/630158](http://blog.csdn.net/shimch/article/details/630158)
### define_syslog_variables
初始化syslog相關的設置項,從這個版本進行了移除。
> define_syslog_variables()只定義了全局變量。常數已經永遠的定義,如果日志模塊加載。你*do not*需要調用這個使用syslog常數。
也就是我們如果想要使用syslog相關的參數,直接調用就行,不需要進行手動初始化。
參考資料
- [http://cn2.php.net/manual/zh/function.define-syslog-variables.php](http://cn2.php.net/manual/zh/function.define-syslog-variables.php)
### 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
參考資料
- [http://php.net/manual/en/misc.configuration.php#ini.syntax-highlighting](http://php.net/manual/en/misc.configuration.php#ini.syntax-highlighting)
### 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 就是為了檢查此類情況而設置的
參考資料
- [http://bbs.csdn.net/topics/40340235](http://bbs.csdn.net/topics/40340235)
### session_is_registered(), session_register() and session_unregister() functions.
這里提到的三個session相關的函數
- session_is_registered()
- session_register()
- session_unregister()
這些是session相關的注冊相關的函數。
*參考資料*
- [http://php.net/manual/en/function.session-is-registered.php](http://php.net/manual/en/function.session-is-registered.php)
- [http://php.net/manual/en/function.session-register.php](http://php.net/manual/en/function.session-register.php)
- [http://php.net/manual/en/function.session-unregister.php](http://php.net/manual/en/function.session-unregister.php)
### y2k_compliance ini option.
這。。。是關于2000的時候的千年蟲的配置項。
參考資料
- [http://www.bkjia.com/PHPjc/852740.html](http://www.bkjia.com/PHPjc/852740.html)
### 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_env_vars 包含了一個以逗號分隔的前綴列表。 在安全模式下,用戶可以僅能修改用該指令設定的前綴名稱的指令。 默認情況下,用戶僅能夠修改以 PHP_ 開頭的環境變量(例如 PHP_FOO=BAR)。 注意:如果此指令是空的,PHP允許用戶設定任意環境變量!
可見這個函數真是危險啊。。。
參考資料
- [http://php.net/manual/zh/function.putenv.php](http://php.net/manual/zh/function.putenv.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\n";
}
}
function hello_world($x) {
echo "Hello, $x\n";
}
//數組中包含了三個,第一個數組,第二個匿名函數,第三個字符串
$callbacks = array(
array('Hello', 'world'),
function ($x) { echo "Hello, $x\n"; },
'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(接口的實現/繼承抽象類不可能)。

zend引擎作為底層,還是需要我理解更深入再去看啦~
### 后記
### 關于PHP
PHP作為流行的腳本語言,上手非常快,但是這并不代表這個一個糟糕的語言,從這個版本的更新記錄,我也看到了每次的改進,以及社區內大家的努力。
這次做ChangeLog的整理大概會寫三個文章共六篇,由于這個Log實在是太長了還是寫一半先發出去比較好~
引用的資料在每個小結后面都有,方便自己和大家查閱。
如果發現描述錯誤,請務必評論或者私信我,如果有錯,發現了就不能再錯下去~
### 關于整理資料
我們依靠網絡,每天在接觸著很多的新聞和資料,對我們來講,從這些里面找出有用的知識并吸收還是有一定難度的,特別是國內糟糕的博客環境,一個文章發布出來之后會有好多網站抄襲抓取,內容還不全,對于初學者會造成負面影響,且珍惜。
### 關于個人成長
當有一個大目標的時候,才可以轉化成小目標進行執行。
執行力永遠放在第一位。
- 前言
- php編寫RSS源
- PHP編寫rss源(續)
- ubuntu 上給PHP安裝擴展 Msgpack 和 Yar
- PHPCMS廣告模塊詳細分析——廣告的生成
- Yii配合Yar在php5.3.3環境下的錯誤以及解決方案
- 【Yaf】Yaf的環境安裝遇到的問題以及解決方案
- 【PHP擴展】centos給PHP安裝擴展
- 【MYSQL】PHPMYADMIN出現的問題以及解決方案
- 【PHP】阿里云升級PHP到5.5詳解
- 【phpMyAdmin】修改配置文件連接到其他服務器
- 【PHP】PHP5.4.0版本ChangeLog詳解(上)
- 【PHP】編譯安裝 PHP5.6.13遇到問題以及解決方案
- 【翻譯】PHP7——新特性
- 【PHP】數組foreach引發的小問題
- 【CURL】PHP的CURL開發項目最佳實踐
- 【PHP】PHP轉換圖片為ico格式源碼
- 【PHP】PHP圖像裁剪縮略裁切類源代碼及使用方法