পৃষ্ঠাসমূহ
Labels
.
Search Your Article
Total Pageviews
Showing posts with label PHP 7 Tutorial. Show all posts
Showing posts with label PHP 7 Tutorial. Show all posts
Wednesday, March 29, 2017
PHP 7 - Performance
As per the Zend
team, following illustrations show the performance comparison of PHP 7
vs PHP 5.6 and HHVM 3.7 on popular PHP based applications.
Magento 1.9
PHP 7 proves itself more than twice as faster, as compared to PHP 5.6 while executing Magento transactions.PHP 7 - Environment Setup
Try it Option Online
We have set up the PHP Programming environment on-line, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.
PHP 7 - Scalar Type Declarations
In PHP 7, a new feature, Scalar type declarations, has been introduced. Scalar type declaration has two options −
- coercive - coercive is default mode and need not to be specified.
- strict - strict mode has to explicitly hinted.
PHP 7 - Return Type Declarations
In PHP 7, a new feature, Return type declarations has been
introduced. Return type declaration specifies the type of value that a
function should return. Following types for return types can be
declared.
- int
- float
- bool
- string
- interfaces
- array
- callable
PHP 7 - Null Coalescing Operator
In PHP 7, a new feature, null coalescing operator (??) has been introduced. It is used to replace the ternary operation in conjunction with isset() function. The Null coalescing operator returns its first operand if it exists and is not NULL; otherwise it returns its second operand.
PHP 7 - Spaceship Operator
In PHP 7, a new feature, spaceship operator has been introduced. It
is used to compare two expressions. It returns -1, 0 or 1 when first
expression is respectively less than, equal to, or greater than second
expression.
PHP 7 - Constant Arrays
Array constants can now be defined using the define() function. In PHP 5.6, they could only be defined using const keyword.
PHP 7 - Anonymous Classes
Anonymous classes can now be defined using new class. Anonymous class can be used in place of a full class definition.
Example
<?php interface Logger { public function log(string $msg); }
PHP 7 - Closure::call()
Closure::call() method is added as a shorthand way to
temporarily bind an object scope to a closure and invoke it. It is much
faster in performance as compared to bindTo of PHP 5.6.
Example - Pre PHP 7
<?php class A { private $x = 1;
PHP 7 - Filtered unserialize()
PHP 7 introduces Filtered unserialize() function to provide
better security when unserializing objects on untrusted data. It
prevents possible code injections and enables the developer to whitelist
classes that can be unserialized.
PHP 7 - IntlChar
In PHP7, a new IntlChar class is added, which seeks to expose
additional ICU functionality. This class defines a number of static
methods and constants, which can be used to manipulate unicode
characters. You need to have Intl extension installed prior to using this class.
PHP 7 - CSPRNG
In PHP 7, following two new functions are introduced to generate
cryptographically secure integers and strings in a cross platform way.
- random_bytes() − Generates cryptographically secure pseudo-random bytes.
- random_int() − Generates cryptographically secure pseudo-random integers.
PHP 7 - Expectations
Expectations are a backwards compatible enhancement to the
older assert() function. Expectation allows for zero-cost assertions in
production code, and provides the ability to throw custom exceptions
when the assertion fails. assert() is now a language construct, where
the first parameter is an expression as compared to being a string or
Boolean to be tested.
PHP 7 - use Statement
From PHP7 onwards, a single use statement can be used to import
Classes, functions and constants from same namespace instead of multiple
use statements.
PHP 7 - Error Handling
From PHP 7, error handling and reporting has been changed. Instead of
reporting errors through the traditional error reporting mechanism used
by PHP 5, now most errors are handled by throwing Error exceptions.
Similar to exceptions, these Error exceptions bubble up until they reach
the first matching catch block. If there are no matching blocks, then a
default exception handler installed with
PHP 7 - Integer Division
PHP 7 introduces a new function intdiv(), which performs integer division of its operands and return the division as int.
PHP 7 - Session Options
From PHP7+, session_start() function accepts an array of options to override the session configuration directives set in php.ini. These options supports session.lazy_write, which is by default on and causes PHP to overwrite any session file if the session data has changed.
PHP 7 - Deprecated Features
Following features are deprecated and may be removed from future releases of PHP.
PHP 4 style constructors
PHP 4 style Constructors are methods having same name as the class they are defined in, are now deprecated, and will be removed in the future. PHP 7 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. Classes implementing a __construct() method are unaffected.PHP 7 - Removed Extensions & SAPIs
Following Extensions have been removed from PHP 7 onwards −
- ereg
- mssql
- mysql
- sybase_ct
Subscribe to:
Posts (Atom)