What has changed in PHP 5.5.x


1.Generators added

  Support for generators has been added via the yield keyword. Generators provide an easy way to implement simple iterators without the overhead or complexity of implementing a class that implements the Iterator interface.
A simple example that reimplements the range() function as a generator (at least for positive step values):

<?phpfunction xrange($start$limit$step 1) {
    for (
$i $start$i <= $limit$i += $step) {
        
yield $i;
    }
}

echo 
'Single digit odd numbers: ';/*
 * Note that an array is never created or returned,
 * which saves memory.
 */
foreach (xrange(192) as $number) {
    echo 
"$number ";
}

echo 
"\n";?>

The above example will output:
Single digit odd numbers: 1 3 5 7 9 
 
 

2.finally keyword added

try-catch blocks now support a finally block for code that should be run regardless of whether an exception has been thrown or not. 

3.New password hashing API

A new password hashing API that makes it easier to securely hash and manage passwords using the same underlying library as crypt() in PHP has been added. See the documentation for password_hash() for more detail.


4.foreach now supports list()

The foreach control structure now supports unpacking nested arrays into separate variables via the list() construct. For example:
<?php
$array 
= [
    [
12],
    [
34],
];

foreach (
$array as list($a$b)) {
    echo 
"A: $a; B: $b\n";
}
?>
The above example will output:
A: 1; B: 2
A: 3; B: 4
Further documentation is available on the foreach manual page.

5.empty() supports arbitrary expressions

Passing an arbitrary expression instead of a variable to empty() is now supported. For example:
<?phpfunction always_false() {
    return 
false;
}

if (empty(
always_false())) {
    echo 
"This will be printed.\n";
}

if (empty(
true)) {
    echo 
"This will not be printed.\n";
}
?>
The above example will output:
This will be printed.

6.array and string literal dereferencing

Array and string literals can now be dereferenced directly to access individual elements and characters:
<?phpecho 'Array dereferencing: ';
echo [
123][0];
echo 
"\n";

echo 
'String dereferencing: ';
echo 
'PHP'[0];
echo 
"\n";?>
The above example will output:
Array dereferencing: 1
String dereferencing: P

7.Class name resolution via ::class

It is possible to use ClassName::class to get a fully qualified name of class ClassName. For example:

<?phpnamespace Name\Space;
class 
ClassName {}

echo 
ClassName::class;

echo 
"\n";?>

The above example will output:
Name\Space\ClassName

and much are added follow the following link
 
view more feature

 

Comments

Popular posts from this blog

How can I debug PHP cURL sessions?

Free icons

Where is the security section of google analytics? “Security Issues” section.