note 120021 deleted from migration70.new-features by sobak

From: Date: Thu, 01 Dec 2016 06:02:32 +0000
Subject: note 120021 deleted from migration70.new-features by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207793@lists.php.net to get a copy of this message
Note Submitter: Maaz Rehman ---- This is the most awaited major release of PHP in almost 11 years . It took 2 years in building and i must say it live up to its expectations . The hopes were really high. The major features that was invented in php 6 till then was added to php 5.4 . Thus php 6 never got released and was abandoned . PHP7 new Features 1-Performance The first biggest feature is not a feature , it is an improvement , The php 7 is really fast , roughly twice as faster than its previous version . There were numerous benchmarks that shows php7 is not just fast , it is very fast . The PHP 7 performance is equivalent to HIPHOP Virtual Machine(HVVM) made by Facebook which uses and leverages byte codes in interpretation. when you have to deploy two servers you can now use 1 , saves cost :) 2-Scalar Type Declaration PHP 7 has 3 modes for handling data types. +None +coercive +Strict +The none means leaving everything as is like in php 5.4, +The Coercive will juggles the type where ever it is declared but it will accept float in place of integer. +The strict as is strict it would really get upset if you send float in place of integer. It displays a fatal error and ends the script. The datatypes are, -int -float -string -bool -array The return type declaration is also been introduced if you want to be explicit about what you want to return and you want to return something from function then you can use any of the 5 types mentioned above. 3-Space Ship Operator It looks like “<==>”, more like an alien ship seen in movies :) returns -1 if left operand is less than the right one return 0 if both operands are equal returns 1 if left operand is greater than 1 This type of operator can be very handy when you are making a binary seach algorithm when you have to write three checks , well not any more we have spaceship for the rescue :) 4-Null Coalescing Operator It returns value i.e not NULL. $default=1; $value=$a ?? $b ?? $default; returns $default to $value. It can be very useful when some thing is not up yet and we have to see second , third ,.. resource and if none is set, it is better to set default so that you can detect what happens and what you have to do from onwards. 5-Anonymous Classes AKA(inner class, nested class,quick class , lambda class ,...) more like a container i.e defined and instantiated at run time . if you require access to an enclosing instance's non-public fields and methods use this one. 6-Constant Arrays Now we have the power to define and declare constants at if-else. Pretty cool hanh ? 7-Unicode Code Prints Now you can insert unicode characters in echo. you can use emoji and emoticon in printing messages . echo “ \u{2764}”; //prints a black heart I personally find it cool to have them B-) 8-Uniform Variable Syntax if you dont have an idea of “variables variables” , this might be hard to understand. $var['maaz']='baaz'; $baaz='var'; ($$baaz)['maaz']; /* $baaz first resolves to $var['maaz'],prints "baaz" in php7 , gives a fatal error in php 5.4 */ 9-intdiv() the function returns integer quotient intdive(5,2); //returns 2 Deprecation With great improvement come some deprecation of pointless features that have outlived its usefulness. 1-Some types of tags have been deprecated. <% ... %> asp styles tag have been deprecated. While <%= ... %> tags are not deprecated , it is still not a good idea to use them when clearly there is an alternative . 2-time zones warning is removed . 3-MYSQL API is to be deprecated by MYSQLi 4-Magic quotes have been deprecated. 5-It is extremely a very bad practice to call instance method statically , well not it has been deprecated . Conclusion I hope that you've enjoyed learning about the new features and improvements in PHP 7. I think it's a great step forward for PHP. And one that will make your development experience much better. Even if you don't need many of the new features,the speed improvement alone makes upgrading to PHP 7 worthwhile.

« previous php.notes (#207793) next »