PHP7 new features manual
/ PHP7棄用功能
PHP7棄用功能
PHP7棄用功能
核心:
- PHP4風(fēng)格的構(gòu)造函數(shù)將被棄用。(和類名同名的方法視為構(gòu)造方法,這是PHP4的語法。)
- 靜態(tài)調(diào)用非靜態(tài)方法將被棄用。
OpenSSL
capture_session_meta選項(xiàng)將被棄用,可以調(diào)用stream_get_meta_data()獲得。
PHP4 風(fēng)格的構(gòu)造函數(shù)
在 PHP4 中類中的函數(shù)可以與類名同名,這一特性在 PHP7 中被廢棄,同時(shí)會(huì)發(fā)出一個(gè) E_DEPRECATED 錯(cuò)誤。當(dāng)方法名與類名相同,且類不在命名空間中,同時(shí)PHP5的構(gòu)造函數(shù)(__construct)不存在時(shí),會(huì)產(chǎn)生一個(gè) E_DEPRECATED 錯(cuò)誤。
實(shí)例
<?php class A { function A() { print('Style Constructor'); } } ?>
以上程序執(zhí)行輸出結(jié)果為:
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in...
以靜態(tài)的方式調(diào)用非靜態(tài)方法
以靜態(tài)的方式調(diào)用非靜態(tài)方法,不再支持:
實(shí)例
<?php class A { function b() { print('Non-static call'); } } A::b(); ?>
以上程序執(zhí)行輸出結(jié)果為:
Deprecated: Non-static method A::b() should not be called statically in...Non-static call
password_hash() 隨機(jī)因子選項(xiàng)
函數(shù)原 salt 量不再需要由開發(fā)者提供了。函數(shù)內(nèi)部默認(rèn)帶有 salt 能力,無需開發(fā)者提供 salt 值。
capture_session_meta SSL 上下文選項(xiàng)
廢棄了 "capture_session_meta" SSL 上下文選項(xiàng)。 在流資源上活動(dòng)的加密相關(guān)的元數(shù)據(jù)可以通過 stream_get_meta_data() 的返回值訪問。