I upgraded one of my server to PHP7 to see how my application will work with it. But personally my design has been about MVC. MVC (Model-View-Controller) is a software design pattern built around the interconnection of three main component types, in a programming language such as PHP, often with a strong focus on object-oriented programming (OOP) software paradigms. On the Other hand is Hip Hop Virtual Machine HHVM, HHVM is a virtual machine for running PHP code as well as for running the new programming language HACK it is a virtual machine based on JIT (Just-In-Time) compilation.HHVM is built by Facebook which I know will work better with the MVC design pattern all I have to do is make sure that HHVN handles the business logic of the web applications. In this post, I am going to explain my experience in running PHP7 on my server and how it compares to HHVM performance.
Performance
Performance is undoubtedly the biggest reason why you should upgrade your servers as soon as a stable version is released. The core refactoring introduced by the phpng RFC makes PHP 7 as fast as (or faster than) HHVM. The official benchmarks are impressive: most real world applications running on PHP 5.6 will run at least twice as fast on PHP 7. Let see the performance of PHP with popular CMS:Return Type Declarations
Return type declarations enable for the return type of a function, method, or closure to be specified. The following return types are supported: string, int, float, bool, array, callable, self (methods only), parent (methods only),Closure, the name of a class, and the name of an interface.
<?php
function arraysSum(array ...$arrays): array
{
return array_map(function(array $array): int {
return array_sum($array);
}, $arrays);
}
print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
/* OutputArray( [0] => 6 [1] => 15 [2] => 24)*/
?>
function arraysSum(array ...$arrays): array
{
return array_map(function(array $array): int {
return array_sum($array);
}, $arrays);
}
print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
/* OutputArray( [0] => 6 [1] => 15 [2] => 24)*/
?>
Group use Declarations
This gives the ability to group multiple use declarations according to the parent namespace. This seeks to remove code verbosity when importing multiple classes, functions, or constants that come under the same namespace.
<?php
// Pre PHP 7 code
use some\namespace\ClassA;
use some\namespace\ClassB;
use some\namespace\ClassC as C;
use function some\namespace\fn_a;
use function some\namespace\fn_b;
use function some\namespace\fn_c;
use const some\namespace\ConstA;
use const some\namespace\ConstB;
use const some\namespace\ConstC;/
// PHP 7+ code
use some\namespace\{ClassA, ClassB, ClassC as C};
use function some\namespace\{fn_a, fn_b, fn_c};
use const some\namespace\{ConstA, ConstB, ConstC};
?>
// Pre PHP 7 code
use some\namespace\ClassA;
use some\namespace\ClassB;
use some\namespace\ClassC as C;
use function some\namespace\fn_a;
use function some\namespace\fn_b;
use function some\namespace\fn_c;
use const some\namespace\ConstA;
use const some\namespace\ConstB;
use const some\namespace\ConstC;/
// PHP 7+ code
use some\namespace\{ClassA, ClassB, ClassC as C};
use function some\namespace\{fn_a, fn_b, fn_c};
use const some\namespace\{ConstA, ConstB, ConstC};
?>
Integer Division with intdiv()
The intdiv() function has been introduced to handle division where an integer is to be returned.
<?php
var_dump(intdiv(10, 3)); // int(3)
?>
var_dump(intdiv(10, 3)); // int(3)
?>
Support for Array Constants in define()
The ability to define array constants was introduced in PHP 5.6 using the const keyword. This ability has now been applied to the define() function too.
<?php
define('ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', 'png']);
?>
define('ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', 'png']);
?>
substr() Return Value Change
substr() will now return an empty string instead of false when the start position of the truncation is equal to the string length.
<?php
var_dump(substr('a', 1));// Pre PHP 7 resultbool(false)// PHP 7+ resultstring(0) ""
?>
var_dump(substr('a', 1));// Pre PHP 7 resultbool(false)// PHP 7+ resultstring(0) ""
?>
Change
Loosening Reserved Word RestrictionsUniform Variable Syntax
Exceptions in the Engine
Throwable Interface
Integer Semantics
JSON Extension Replaced with JSOND
ZPP Failure on Overflow
Fixes to foreach()'s Behaviour
Changes to list()'s Behaviour
Changes to Division by Zero Semantics
Fixes to Custom Session Handler Return Values
Deprecation of PHP 4-Style Constructors
Removal of date.timezone Warning
Removal of Alternative PHP Tags : The alternative PHP tags <% (and <%=), %>, have now been removed.
Removal of Multiple Default Blocks in Switch Statements
Removal of Redefinition of Parameters with Duplicate Names
Removal of Dead Server APIs
Removal of Hex Support in Numerical Strings
Removal of Deprecated Functionality:
All Deprecated functionality has been removed, most notably:
The original mysql extension (ext/mysql)
The ereg extension (ext/ereg)
Assigning new by reference
Scoped calls of non-static methods from an incompatible $this context (such as Foo::bar() from outside a class, where bar() is not a static method)
Thanks!
Your feedback helps us improve tutorials.
No comments:
Post a Comment