What is new in PHP 5.5 - HuyenNT

  • 1,528 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,528
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. What's new in php 5.5 By: Nguyen Thi Huyen-framgia
  • 2. 1. Installation. 2. New features & demo. 3. References.
  • 3. 1. Installation. - Access website http://bitnami.com/stack/lamp/installer download “LAMP Stack Dev 5.5.1-0 (64 bit)”. - Install “./bitnami-lampstack-5.5.1-0-dev-linux-x64- installer.run” in terminal.
  • 4. 2. New features & demo. a) Generators. - Generators are one of the most eagerly anticipated new features. - They provide a way to handle iteration without having to write a class that implements the Iterator interface. - Generators derive their functionality from the new “yield” keyword. A generator looks very similar to a normal function, but instead of returning a single value, a generator may yield any number of values.
  • 5. b) Finally. PHP 5.5 adds support for the finally keyword. finally allows developers to specify code to be run at the end of try and catch blocks, regardless of whether an exception was thrown or not, before the normal execution flow resumes. - If you use “finally”, you won use “catch”: //without catch function example() { try { //do something that throws an exeption } finally { //this code will be executed even when the exception is executed } }
  • 6. - Code within the FINALLY block will be executed even if the “return” is called inner try/catch block. - Code within the FINALLY block will be executed even if haven't any matching catch block.
  • 7. c) Array and String Literal Dereferencing. - Array and string literals can now be dereferenced using array access syntax: <?php // array dereferencing - returns 3 echo [1, 3, 5, 7][1]; // string dereferencing - returns "l" echo "hello"[3]; ?> - This feature was added primarily to improve the consistency of the language.There are some interesting applications to consider, such as the following: <?php $randomChar = "abcdefg0123456789"[mt_rand(0, 16)]; ?>
  • 8. d) Changes to foreach. The list() construct in PHP allows the values of an array to be easily assigned to variables. It’s now possible to use list() with multidimensional arrays within foreach loops: <?php $data = [ ["sea", "blue"], ["grass", "green"] ]; foreach ($data as list($object, $description)) { echo "The $object is $descriptionn"; } ?> This is a powerful new feature that has the potential to make iterating through nested arrays much easier and cleaner.
  • 9. e) Password Hashing. - The new password hashing API is one of the most important and useful features added in PHP 5.5. In the past, developers have had to rely on the somewhat confusing crypt() function. public function generatePasswordHash($raw_password) { return crypt($raw_password, Randomness::blowfishSalt()); } public function isValidPassword($raw_password) { return crypt($raw_password, $this->password) === $this->password; }
  • 10. - The new API introduces two new functions: password_hash() -Creates a password hash password_verify()-Verifies that a password matches a hash. <?php echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."n"; ?> <?php // See the password_hash() example to see where this came from. $hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq'; if (password_verify('rasmuslerdorf', $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } ?>
  • 11. Moreover: Using empty() with Function Calls and Expressions, Class Name Resolution.
  • 12. 3. References. http://www.sitepoint.com/whats-new-in-php-5-5/. http://www.php.net/manual/en/book.password.php. http://www.adayinthelifeof.nl/2013/02/12/php5-5-trycatchfinally/
  • 13. Thank you for listening !