Which is the new operator added in php 7?
Scalar type declarations Scalar type declarations come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (string), integers ( Show
The above example will output: To enable strict mode, a single Full documentation and examples of scalar type declarations can be found in the type declaration reference. Return type declarationsPHP 7 adds support for return type declarations. Similarly to argument type declarations, return type declarations specify the type of the value that will be returned from a function. The same types are available for return type declarations as are available for argument type declarations.
The above example will output: Array ( [0] => 6 [1] => 15 [2] => 24 ) Full documentation and examples of return type declarations can be found in the return type declarations. reference. Null coalescing operator The null coalescing operator (
Spaceship operatorThe spaceship operator is used for comparing two expressions. It returns -1, 0 or 1 when $a is respectively less than, equal to, or greater than $b. Comparisons are performed according to PHP's usual type comparison rules.
echo 1.5 <=> 1.5; // 0 Constant arrays using define() Array constants can now be defined with define(). In PHP 5.6, they
could only be defined with
ANIMALS[1]; // outputs "cat" Anonymous classes Support for anonymous classes has been added via
Application { The above example will output: object(class@anonymous)#2 (0) { } Full documentation can be found in the anonymous class reference. Unicode codepoint escape syntaxThis takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.
The above example will output: ª ª (same as before but with optional leading 0's) 香 Closure::call()Closure::call() is a more performant, shorthand way of temporarily binding an object scope to a closure and invoking it.
The above example will output: Filtered unserialize()This feature seeks to provide better security when unserializing objects on untrusted data. It prevents possible code injections by enabling the developer to whitelist classes that can be unserialized.
IntlCharThe new IntlChar class seeks to expose additional ICU functionality. The class itself defines a number of static methods and constants that can be used to manipulate unicode characters.
('%x', IntlChar::CODEPOINT_MAX); The above example will output: 10ffff COMMERCIAL AT bool(true) In order to use this class, the Intl extension must be installed. ExpectationsExpectations are a backwards compatible enhancement to the older assert() function. They allow for zero-cost assertions in production code, and provide the ability to throw custom exceptions when the assertion fails. While the old API continues to be maintained for compatibility, assert() is now a language construct, allowing the first parameter to be an expression rather than just a string to be evaluated or a bool value to be tested.
CustomError extends AssertionError {}assert(false, new CustomError('Some error message'));
The above example will output: Fatal error: Uncaught CustomError: Some error message Full details on this feature, including how to configure it in both development and production environments, can be found in the expectations section of the assert() reference. Group use declarations Classes, functions and constants being imported from the same
some\namespace\fn_a; Generator Return Expressions This feature builds upon the generator functionality introduced into PHP 5.5. It enables for a
= (function() { The above example will output: Being able to explicitly return a final value from a generator is a handy ability to have. This is because it enables for a final value to be returned by a generator (from perhaps some form of coroutine computation) that can be specifically handled by the client code executing the generator. This is far simpler than forcing the client code to firstly check whether the final value has been yielded, and then if so, to handle that value specifically. Generator delegation Generators can now delegate to another generator, Traversable object or array automatically, without needing to write boilerplate in the outermost generator by using the
gen2() The above example will output: Integer division with intdiv()The new intdiv() function performs an integer division of its operands and returns it.
The above example will output: Session optionssession_start() now accepts an array of options that override the session configuration directives normally set in php.ini. These options have also been expanded to support session.lazy_write, which is on by default and causes PHP to only overwrite any session file if the session data has changed, and For example, to set session.cache_limiter to
preg_replace_callback_array()The new preg_replace_callback_array() function enables code to be written more cleanly when using the preg_replace_callback() function. Prior to PHP 7, callbacks that needed to be executed per regular expression required the callback function to be polluted with lots of branching. Now, callbacks can be registered to each regular expression using an associative array, where the key is a regular expression and the value is a callback. CSPRNG FunctionsTwo new functions have been added to generate cryptographically secure integers and strings in a cross platform way: random_bytes() and random_int(). list() can always unpack objects implementing ArrayAccessPreviously, list() was not guaranteed to operate correctly with objects implementing ArrayAccess. This has been fixed. Other Features
PawelD ¶ 6 years ago
Adrian Wiik ¶ 2 years ago
Julian Sawicki ¶ 2 years ago
Julian Sawicki ¶ 2 years ago
$add10 = add(10); ricasiano at gmail dot com ¶ 2 years ago
TerryE ¶ 5 years ago
nevercode at pm dot me ¶ 2 years ago
What are the new feature in PHP 7?Key Takeaways. PHP 7.0 added scalar type declarations for strings, integers, floating-point numbers, and booleans.. PHP 7.0 added support for return type declarations.. PHP 7.1 added support for nullable parameter types and return types.. void is a valid return type as of PHP 7.1.. What is new in PHP latest version?Latest Versions Come With More Features
One, in particular, highlights the example of not only a new feature, but also productivity. Constructor property promotion is new in PHP 8.0 and offers developers an opportunity to move quicker when defining the constructor properties of an object.
What is the difference between PHP 7 and PHP 8?PHP 8 brings a host of new features improvements, functions, and deprecations to the language compared to PHP 7. Among all of these new features, the JIT compiler is the one sharing the limelight.
What are the new features in PHP 8?PHP 8 Improvements and New Features. Constructor Property Promotion.. Validation for Abstract Trait Methods.. Incompatible Method Signatures.. Arrays Starting With a Negative Index.. Union Types 2.0.. Consistent Type Errors for Internal Functions.. throw Expression.. Weak Maps.. |