📜 ⬆️ ⬇️

What PHP 5.5 looks like

PHP 5.4 was published four months ago, so it's probably too early to look at the new version of PHP. Nevertheless, I would like to do for everyone who is not subscribed to the internal mailing list , a small preliminary overview of what PHP 5.5 might look like.

However, you must understand: PHP 5.5 is still at an early stage of development, so no one knows what it will look like in the end. All that is written here is just a sentence. I'm sure not all of this will be in PHP 5.5, or will, but not in this form.

So don't get too excited.
')
Now, without further ado, a list of features that are being worked on in PHP 5.5:

backward compatibility


Let's start with two changes that are already in master and affect backward compatibility (at least to some extent):

Failure to support Windows XP and 2003

Status: landed; Responsible: Pierre Joye

PHP 5.5 no longer supports Windows XP and 2003. These systems are about ten years old, so PHP abandoned them.

Modifier / e declared obsolete

: 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 , , , .

/ , .

!

Source: https://habr.com/ru/post/147674/


All Articles