your apps see up to 2x faster performance and 50% better memory consumption than PHP 5.6, allowing you to serve more concurrent users without adding any hardware. Designed and refactored for today’s workloads, PHP 7 is the ultimate choice for web developers today.
Removal of Deprecated Functionality 02 Removal of Alternative PHP Tags 03 Removal of date.timezone Warning 04 PHP4 Constructor deprecated in favour of __construct() 05 JSON Extension Replaced with JSOND 06 Removal of Multiple Default Blocks in Switch Statements
names within classes, interfaces, and traits are now allowed. This reduces the surface of BC breaks when new keywords are introduced and avoids naming restrictions on APIs. // 'new', 'private', and 'for' were previously unusable Project::new('Project Name’)->private() ->for('purpose here’) ->with('username here');
compares 2 values and returns a given result. These results can be -1, 0 or 1. var_dump(123 <=> 456); // int(-1) Returns a integer 1 - left hand operator 0 - equal -1 - right hand operator Able to compare - strings - numbers - arrays
for the isset() function. Developers had to write a lot of similar if statements so the community decided it would be wise to implement a short way to remove complexity in your code. if (isset($_GET[‘route’])) { $route = $_GET[‘route']; } else { $route = ‘index’; } $route = isset($_GET['route']) ? $_GET['route'] : 'index'; $route = $_GET['route'] ?? 'index';
is that PHP is to loose. This gives margin for errors in your code. Scalar type declarations try to handle this issue. function sumOfInts(int ...$ints) { return array_sum($ints); } var_dump(sumOfInts(2, '3', 4.1)); // int(9) declare(strict_types=1); Coercive mode VS Strict mode
is that PHP is to loose. This gives margin for errors in your code. Scalar type declarations try to handle this issue. function sumOfInts(int …$ints): array { return array_sum($ints); }
becomes use some\namespace\{ClassA, ClassB, ClassC as C}; Group use declarations If you have a large scale project, your code will be separated in multiple classes. Using these classes will result in lots of ‘use’ statements at the top of your class. PHP7 allows you to group these use statements.
a fatal and recoverable error (E_ERROR and E_RECOVERABLE_ERROR) occurs, rather than halting script execution. Fatal errors still exist for certain conditions, such as running out of memory, and still behave as before by immediately halting script execution. An uncaught exception will also continue to be a fatal error in PHP 7. This means if an exception thrown from an error that was fatal in PHP 5.x goes uncaught, it will still be a fatal error in PHP 7. interface Throwable |- Exception class implements Throwable |- ... |- Error class implements Throwable |- TypeError extends Error |- ParseError extends Error |- AssertionError extends Error |- ArithmeticError extends Error |- DivisionByZeroError extends ArithmeticError