PHP 5.5の外観

PHP 5.4は4か月前に公開されたので、おそらくPHPの新しいバージョンを見るには時期尚早です。 それでも、 内部メーリングリストに登録していないすべての人のために、PHP 5.5がどのように見えるかについての小さな予備レビューをしたいと思います。



ただし、理解する必要があります。PHP5.5はまだ開発の初期段階にあるため、最終的にどのように見えるかは誰にもわかりません。 ここに書かれているのは単なる提案です。 このすべてがPHP 5.5にあるとは限りませんし、そうなるとは限りませんが、この形式ではありません。



興奮しすぎないでください。



さて、苦労することなく、PHP 5.5で機能している機能のリスト:



下位互換性



すでにmasterにヒットし、後方互換性に影響する(少なくともある程度)2つの変更から始めましょう。



Windows XPおよび2003のサポートの終了


ステータス:着陸。 担当:ピエールジョワイ



PHP 5.5はWindows XPおよび2003をサポートしなくなりました。これらのシステムは約10年前であるため、PHPはそれらを放棄しました。



修飾子/ eは非推奨です


: landed; : Nikita Popov



e



preg_replace



PHP, . , , . deprecated



PHP 5.5. preg_replace_callback



. RFC.





:



boolval()


: landed; : Jille Timmermans



PHP strval



, intval



floatval



. boolval



. , (bool)



, .



hash_pbkdf2()


: landed; : Anthony Ferrara



PBKDF2 «Password-Based Key Derivation Function 2» , , . , . RFC.



intl


: landed; : Gustavo André dos Santos Lopes



intl. , IntlCalendar



, IntlGregorianCalendar



, IntlTimeZone



, IntlBreakIterator



, IntlRuleBasedBreakIterator



, IntlCodePointBreakIterator



. intl, , , Calendar BreakIterator.



array_column()


: proposed; : Ben Ramsey



array_column



( array_pluck



), :



<?php

$userNames = array_column($users, 'name');
//   
$userNames = [];
foreach ($users as $user) {
    $userNames[] = $user['name'];
}

      
      





, .



API


: proposed; : Anthony Ferrara



( LinkedIn .) , . BCrypt, , , sha1



.



, crypt



. , , API :



<?php

$password = "foo";

//  
$hash = password_hash($password, PASSWORD_BCRYPT);

//  
if (password_verify($password, $hash)) {
    //  !
} else {
    //  !
}

      
      





API , RFC.





: .





: landed; : Xinchen Hui



, . :



<?php

function randomHexString($length) {
    $str = '';
    for ($i = 0; $i < $length; ++$i) {
        $str .= "0123456789abcdef"[mt_rand(0, 15)]; // dereference  
    }
}

function randomBool() {
    return [false, true][mt_rand(0, 1)]; // dereference  
}

      
      





, , . . RFC.



empty()


: landed; : Nikita Popov



empty()



, . , empty($this->getFriends())



. PHP 5.5 . . RFC.





: proposed; : Ralph Schindler



PHP 5.3 . :



<?php

use Some\Deeply\Nested\Namespace\FooBar;

//  ,       `FooBar`
$reflection = new ReflectionClass('FooBar');

      
      





FooBar::class



, :



<?php

use Some\Deeply\Nested\Namespace\FooBar;

// ,   FooBar::class   "Some\\Deeply\\Nested\\Namespace\\FooBar"
$reflection = new ReflectionClass(FooBar::class);

      
      





RFC.





: proposed; : Stas Malyshev



, , .



RFC:



function create_query($where, $order_by, $join_type='', $execute = false, $report_errors = true) { ... }







$report_errors = false



. :



create_query("deleted=0", "name", default, default, false);







. , , . 12 .





: proposed; : Anthony Ferrara



5.4, - . , PHP, .: Scalar typehints are harder than you think.



PHP 5.5 , , .



, , . 123



, 123.0



, "123"



int



, " "



. .



function foo(int $i) { ... }

foo(1);      // $i = 1
foo(1.0);    // $i = 1
foo("1");    // $i = 1
foo("1abc"); //   ,   $i = 1   notice
foo(1.5);    //   ,   $i = 1   notice
foo([]);     // 
foo("abc");  // 

      
      





Getters setters


: proposed; : Clint Priest



getXYZ()



setXYZ($value)



, . , , :



<?php

class TimePeriod {
    public $seconds;

    public $hours {
        get { return $this->seconds / 3600; }
        set { $this->seconds = $value * 3600; }
    }
}

$timePeriod = new TimePeriod;
$timePeriod->hours = 10;

var_dump($timePeriod->seconds); // int(36000)
var_dump($timePeriod->hours);   // int(10)

      
      





​​ , read-only . , RFC.





: proposed; : Nikita Popov



, . , .



, range



:



<?php

function *xrange($start, $end, $step = 1) {
    for ($i = $start; $i < $end; $i += $step) {
        yield $i;
    }
}

foreach (xrange(10, 20) as $i) {
    // ...
}

      
      





xrange



, range



: , , .



RFC.



-


: proposed; : Nikita Popov



:



$firstNames = [foreach ($users as $user) yield $user->firstName];







:



$firstNames = [];
foreach ($users as $user) {
    $firstNames[] = $user->firstName;
}

      
      





:



$underageUsers = [foreach ($users as $user) if ($user->age < 18) yield $user];







- , , , .



.





, , PHP 5.5. , , PHP 5.5 , , , .



/ , .



!



All Articles