Migrating from PHP 5.4.x to PHP 5.5.x

Source: Internet
Author: User

php5.4.x migration to php5.5.x migration to PHP5


1 Don't want a post-compatible change

(1) Not supported for Windows XP and 2003

(2) Pack and unpack () function add "Z" mode

(3) Removing PHP log GUIDs

Related functions

Php_log_guid (), Php_egg_log_guid (), Php_real_logo_guid (), Zend_log_guid ()

Related Simple cases

Echo Php_logo_guid ();

Echo '

'? = '. Php_logo_guid (). ' alt= ' PHP Logo! '/> ';


Echo '

'? = '.  Zend_logo_guid (). "alt=" Zend Logo! "/>";


Var_dump (Php_egg_logo_guid ());


Var_dump (Php_real_logo_guid ());

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/09/wKiom1YOws3TO2bQAADpwv9VPmQ134.jpg "title=" capture. PNG "alt=" Wkiom1yows3to2bqaadpwv9vpmq134.jpg "/>


2 new features

(1) Generator yield keyword

http://php.net/manual/zh/language.generators.overview.php

The generator provides an easier way to implement a simple object iteration, comparing the way that the definition class implements the Iterator interface, with significantly reduced performance overhead and complexity. The generator allows you to write code in a foreach code block to iterate over a set of data without having to create an array in memory, which will limit your memory to a maximum or take up considerable processing time. Instead, you can write a generator function, just like a normal custom function, and the normal function returns only once differently, and the generator can yield multiple times as needed to generate values that need to be iterated. A simple example is to use the generator to re-implement the range () function. The standard range () function needs to generate an array in memory that contains every value within its scope, and then returns the array, resulting in multiple large arrays. For example, calling range (0, 1000000) will result in memory consumption exceeding MB. As an alternative, we can implement a xrange () generator that requires only enough memory to create the Iterator object and keep track of the generator's current state internally, which requires less than 1K bytes of memory.


<?php

function xrange ($start, $limit, $step = 1) {

if ($start < $limit) {

if ($step <= 0) {

throw new Logicexception (' Step must be +ve ');

}

for ($i = $start; $i <= $limit; $i + = $step) {

Yield $i;

}

} else {

if ($step >= 0) {

throw new Logicexception (' Step must be-ve ');

}

for ($i = $start; $i >= $limit; $i + = $step) {

Yield $i;

}

}

}

/*

* Note that the result of the following range () and xrange () output is the same.

*/

echo ' single digit odd numbers from range (): ';

foreach (Range (1, 9, 2) as $number) {

echo "$number";

}

echo "\ n";


echo ' single digit odd numbers from xrange (): ';

foreach (Xrange (1, 9, 2) as $number) {

echo "$number";

}

?>


Single digit odd numbers from range (): 1 3 5 7 9

Single digit odd numbers from xrange (): 1 3 5 7 9


(2) Finally keyword

In the error-handling statement Try...catch Add the finally and C#,java similar

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/09/wKiom1YOxGXjJmayAAC2N2WGzBQ292.jpg "style=" float: none; "title=" capture. PNG "alt=" Wkiom1yoxgxjjmayaac2n2wgzbq292.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/06/wKioL1YOxHTAJwYuAABaGB6tJBs901.jpg "style=" float: none; "Title=" Captures 1. PNG "alt=" Wkiol1yoxhtajwyuaabagb6tjbs901.jpg "/>


(3) foreach now supports list ()

The foreach control structure now supports separating nested arrays into separate variables through the list () construct. For example:

<?php

$array = [

[1, 2],

[3, 4],

];


foreach ($array as list ($a, $b)) {

echo "A: $a; B: $b \ n ";

}

?>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/06/wKioL1YOxhzAdLaoAAA-R7LZGmA388.jpg "title=" capture. PNG "alt=" Wkiol1yoxhzadlaoaaa-r7lzgma388.jpg "/>

(4) empty () supports arbitrary expressions

Empty () now supports passing in an arbitrary expression, not just a variable. For example:

php5.5.x Previous Versions

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/09/wKiom1YOx7jjkUcdAACVAzt-MYg333.jpg "style=" float: none; "title=" capture. PNG "alt=" Wkiom1yox7jjkucdaacvazt-myg333.jpg "/>

>=php5.5.x

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/06/wKioL1YOx8fRvznFAABTfJWUVQA383.jpg "style=" float: none; "Title=" Captures 1. PNG "alt=" Wkiol1yox8frvznfaabtfjwuvqa383.jpg "/>

(5) The non-variable array and string can also support the subscript to obtain the

<?php

Echo ' Array dereferencing: ';

echo [1, 2, 3] [0];

echo "\ n";


Echo ' String dereferencing: ';

Echo ' PHP ' [0];

echo "\ n";

?>

Array dereferencing:1

String Dereferencing:p


This article is from the "Ouyangjun" blog, make sure to keep this source http://ouyangjun.blog.51cto.com/10284323/1699977

Migrating from PHP 5.4.x to PHP 5.5.x

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.